简而言之,该应用程序旨在执行以下操作:
代码方面,它看起来像这样:
//ImageView is the UIImageView subview that will hold the selected photo image.
//This code works ok, but I'd rather have a higher resolution photo.
[imageView setClipsToBounds:YES];
[imageView setContentMode:UIViewContentModeScaleAspectFill];
[imageView setImage:[UIImage imageWithCGImage:[selectedPhoto thumbnail]];
现在,这是我尝试使用更高分辨率图像的代码,但是然后imageView中的图像旋转-90度:
[imageView setClipsToBounds:YES];
[imageView setContentMode:UIViewContentModeScaleAspectFill];
//HIGH RESOLUTION IMAGE
ALAssetRepresentation *rep = [selectedPhoto defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
if (iref)
{
UIImage *largeImage = [Utilities imageWithImage:[UIImage imageWithCGImage:iref] scaledToSize:CGSizeMake(CGImageGetWidth(iref)/4, CGImageGetHeight(iref)/4)];
[imageView setImage:largeImage];
}
在那里调用的imageWithImage:函数看起来像这样:
+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
如上所述,iPhone相机以横向拍摄的照片都可以。但是,以人像相机拍摄的照片会以某种方式旋转-90度。
我怎样才能使每张照片(无论是纵向还是横向拍摄)在我的ImageView上正确显示?
任何帮助将不胜感激!谢谢!
答案 0 :(得分:4)
我在这里找到了答案!
ALAssetRepresentation fullResolutionImage's UIImageOrientation is wrong
我现在正在这样做:
UIImage * largeImage = [[UIImage alloc] initWithCGImage:iref scale:4 orientation:(UIImageOrientation)rep.orientation];