【发布时间】:2012-03-08 08:39:21
【问题描述】:
简而言之,该应用旨在执行以下操作:
- 用户将从 iPhone 中的照片中进行选择(通过 ALAssets)。这部分很好。
- 所选照片将出现在另一个视图中,位于一个较小的矩形子视图中。
- 使用 ALAsset 缩略图时,图像在子视图中正确显示。但是,分辨率很差,所以我尝试使用更高分辨率的图像。
- 当使用全分辨率图像,然后将其放入视图中时,任何肖像照片都会逆时针旋转 90 度。
在代码方面,它看起来像这样:
//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 上正确显示?
任何帮助将不胜感激!谢谢!
【问题讨论】:
-
我在这里找到了答案! stackoverflow.com/questions/3648632/…我现在正在这样做:ALAssetRepresentation *rep = [selectedPhoto defaultRepresentation]; CGImageRef iref = [rep fullResolutionImage]; UIImage *largeImage = [[UIImage alloc] initWithCGImage:iref scale:4orientation:rep.orientation]; PS。我还不能回答这个问题,因为没有足够的时间过去。