// 添加 UIImage 的分類 ResizeUIImage @implementation UIImage (ResizeUIImage) /** 重繪圖片大小 @param size 要獲得的圖片的尺寸大小 @return 獲得的指定尺寸大小的圖片 */ - (UIImage *)resizeImageToSize:(CGSize)size { // change from UIGraphicsBeginImageContext(size) to suit scale > 1 UIGraphicsBeginImageContextWithOptions(size, false, 0); [self drawInRect:CGRectMake(0, 0, size.width, size.height)]; UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; } @end // 從新設置圖片的大小 image = [image resizeImageToSize:CGSizeMake(100, 200)];