【发布时间】:2013-04-23 18:21:30
【问题描述】:
我有一个使用相机的 iPad 应用程序。原始图像为 480 x 640。我正在尝试将其调整为 124 x 160,然后使用我在互联网上找到的以下代码将其存储在 CoreData 中:
- (UIImage *)resizeImage:(UIImage*)image newSize:(CGSize)newSize {
CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));
CGImageRef imageRef = image.CGImage;
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
// Set the quality level to use when rescaling
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, newSize.height);
CGContextConcatCTM(context, flipVertical);
// Draw into the context; this scales the image
CGContextDrawImage(context, newRect, imageRef);
// Get the resized image from the context and a UIImage
CGImageRef newImageRef = CGBitmapContextCreateImage(context);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
CGImageRelease(newImageRef);
UIGraphicsEndImageContext();
return newImage;
}
图像被逆时针旋转 90 度返回给我,我不明白为什么。我试过注释掉这个声明:
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, newSize.height);
但这没什么区别。这里有什么问题?
【问题讨论】:
-
图像的旋转不是元数据的属性,而不是像素的实际重新对齐吗?至少我认为它适用于使用 iPod/iPhone/iPad 的相机(以及许多其他消费类相机)拍摄的照片
-
靠复制粘贴代码sn-p生存的人死于复制粘贴代码sn-p。这里要做的就是思考。 UIImage 有方向信息。 CGImage 没有。因此,您将这些信息丢弃并且永远不会恢复它。
-
好的...我已经尝试了这里建议的所有内容,但没有任何帮助...我明白马特在说什么,但这无济于事...我只想节省空间通过缩放图像...似乎这是一项收效甚微的大量工作...
-
UIImage 的方向是否已设置,如果设置,则设置为什么?
-
不,这是 iPad 相机在纵向模式下拍摄的原始 UIImage。
标签: ios objective-c uiimage