大家好,
我在转动纵向UIImage
(即WIDTH < HEIGHT
)时出现问题,其某种方向的取向等于UIImageOrientationRight
。我不确定这是怎么回事,但是我的库中用iPhone 4拍摄的一些图像就会发生这种情况。
这是我的代码(执行工作,但仅当方向等于UIImageOrientationUp
时):
UIGraphicsBeginImageContextWithOptions(rotatedScaledRect.size, NO, 0.0);
CGContextRef myContext = UIGraphicsGetCurrentContext();
CGContextSetInterpolationQuality(myContext, kCGInterpolationHigh);
CGContextTranslateCTM(myContext,
(rotatedScaledRect.size.width/2),
(rotatedScaledRect.size.height/2));
CGContextConcatCTM(myContext, transformation);
CGContextScaleCTM(myContext, 1.0, -1.0);
CGContextDrawImage(myContext, CGRectMake(-roundf(newImage.size.width / 2), -roundf(newImage.size.height / 2), newImage.size.width, newImage.size.height), [newImage CGImage]);
newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
我需要应用CGContextConcatCTM
,因为我对图像进行了几次连接转换。
我尝试了几种不同的方法无济于事。
提前感谢您的帮助。
答案 0 :(得分:0)
首先,请原谅我的英语,因为这不是我的母语。我希望现在回答这个问题还不晚!
由于这个原因,我在用iPhone或iPod cammera拍摄的照片中加载了类似的问题。如果是你的情况,你可以在这里找到一些信息:https://discussions.apple.com/thread/2495567?start=30&tstart=0,特别是答案说“Apple选择使用EXIF数据中的Orientation标志来通知显示图像的程序如何旋转它图像显示正确。“
因此,要从使用iPhone Cammera的图书馆加载照片,您必须这样做:
ALAssetRepresentation *assetRep = [photo defaultRepresentation];
CGImageRef imageRef = [assetRep fullResolutionImage];
UIImage *image = [UIImage imageWithCGImage:imageRef scale:[assetRep scale] orientation:[assetRep orientation]];
其中photo是从库中获取的ALAsset对象。
嗯,我希望这有帮助!