【发布时间】:2015-11-20 02:53:34
【问题描述】:
我正在尝试使用 NYXImageKit 调整 UIImage 的大小,这会导致图像的数据大小增加
P.S.: originalImage 的尺寸是 1024 * 1024
var originalImage = image;
//originalImage SIZE 108 KB
var resizedImage = image.scaleToFillSize(CGSize(width: 256, height: 256));
//resizedImage BECAME 620 KB
有什么想法吗?
以下代码来自 NYXImageKit 类 UIImage+Resizing.m
-(UIImage*)scaleToFillSize:(CGSize)newSize
{
size_t destWidth = (size_t)(newSize.width * self.scale);
size_t destHeight = (size_t)(newSize.height * self.scale);
if (self.imageOrientation == UIImageOrientationLeft
|| self.imageOrientation == UIImageOrientationLeftMirrored
|| self.imageOrientation == UIImageOrientationRight
|| self.imageOrientation == UIImageOrientationRightMirrored)
{
size_t temp = destWidth;
destWidth = destHeight;
destHeight = temp;
}
/// Create an ARGB bitmap context
CGContextRef bmContext = NYXCreateARGBBitmapContext(destWidth, destHeight, destWidth * kNyxNumberOfComponentsPerARBGPixel, NYXImageHasAlpha(self.CGImage));
if (!bmContext)
return nil;
/// Image quality
CGContextSetShouldAntialias(bmContext, true);
CGContextSetAllowsAntialiasing(bmContext, true);
CGContextSetInterpolationQuality(bmContext, kCGInterpolationHigh);
/// Draw the image in the bitmap context
UIGraphicsPushContext(bmContext);
CGContextDrawImage(bmContext, CGRectMake(0.0f, 0.0f, destWidth, destHeight), self.CGImage);
UIGraphicsPopContext();
/// Create an image object from the context
CGImageRef scaledImageRef = CGBitmapContextCreateImage(bmContext);
UIImage* scaled = [UIImage imageWithCGImage:scaledImageRef scale:self.scale orientation:self.imageOrientation];
/// Cleanup
CGImageRelease(scaledImageRef);
CGContextRelease(bmContext);
return scaled;
}
【问题讨论】:
-
scaleToFillSize (CGSize size)的邮政编码以及您使用的是什么类型的图片? -
已编辑。请检查@HarvantS。
-
Image quality添加是原因。 -
好的,请问我应该如何编辑代码@HarvantS。
-
我已经调整大小并压缩了大约 240K 的 jpeg 数据,然后重构为
UIImage(data:),然后它的 jpeg 数据变成了大约 600K!我已经考虑了点大小和像素大小,它们都是正确的。我认为 UIImage(data:) 实际上做了一些平滑等使图像数据更大。
标签: ios objective-c swift uiimage nsdata