更改UIImage尺寸

 1 - (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)newsize
 2 {
 3     // 建立一個bitmap的context
 4         
 5     // 並把它設置成爲當前正在使用的context
 6         
 7     UIGraphicsBeginImageContext(newsize);
 8         
 9     // 繪製改變大小的圖片
10         
11     [img drawInRect:CGRectMake(0, 0, newsize.width, newsize.height)];
12         
13     // 從當前context中建立一個改變大小後的圖片
14         
15     UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
16         
17     // 使當前的context出堆棧
18         
19     UIGraphicsEndImageContext();
20         
21     // 返回新的改變大小後的圖片
22         
23     return scaledImage;
24 }
相關文章
相關標籤/搜索