所以在我的应用程序中,由于某种原因,一些照片显示为颠倒.我检查了他们的imageOrIEntation属性,它们都是0(意思是它们是UIImageOrIEntationUp).这意味着我甚至不知道我需要旋转哪些照片.
发生了什么,我怎么知道哪些照片需要旋转?谢谢
解决方法 UIImage有一个属性imageOrIEntation,它指示UIImageVIEw和其他UIImage使用者旋转原始图像数据.这个标志很有可能被保存到上传的jpeg图像中的exif数据,但是用来查看它的程序并没有遵守该标志.要在上传时旋转UIImage以正确显示,您可以使用如下类别:
在.h文件中
UIImagefixOrIEntation.h
@interface UIImage (fixOrIEntation)- (UIImage *)fixOrIEntation;@end
UIImagefixOrIEntation.m
@implementation UIImage (fixOrIEntation)- (UIImage *)fixOrIEntation { // No-op if the orIEntation is already correct if (self.imageOrIEntation == UIImageOrIEntationUp) return self; // We need to calculate the proper transformation to make the image upright. // We do it in 2 steps: Rotate if left/Right/Down,and then flip if Mirrored. CGAffinetransform transform = CGAffinetransformIDentity; switch (self.imageOrIEntation) { case UIImageOrIEntationDown: case UIImageOrIEntationDownMirrored: transform = CGAffinetransformTranslate(transform,self.size.wIDth,self.size.height); transform = CGAffinetransformRotate(transform,M_PI); break; case UIImageOrIEntationleft: case UIImageOrIEntationleftMirrored: transform = CGAffinetransformTranslate(transform,0); transform = CGAffinetransformRotate(transform,M_PI_2); break; case UIImageOrIEntationRight: case UIImageOrIEntationRightmirrored: transform = CGAffinetransformTranslate(transform,self.size.height); transform = CGAffinetransformRotate(transform,-M_PI_2); break;}switch (self.imageOrIEntation) { case UIImageOrIEntationUpMirrored: case UIImageOrIEntationDownMirrored: transform = CGAffinetransformTranslate(transform,0); transform = CGAffinetransformScale(transform,-1,1); break; case UIImageOrIEntationleftMirrored: case UIImageOrIEntationRightmirrored: transform = CGAffinetransformTranslate(transform,self.size.height,1); break;}// Now we draw the underlying CGImage into a new context,applying the transform// calculated above.CGContextRef ctx = CGBitmapContextCreate(NulL,CGImageGetBitsPerComponent(self.CGImage),CGImageGetcolorSpace(self.CGImage),CGImageGetBitmAPInfo(self.CGImage));CGContextConcatCTM(ctx,transform);switch (self.imageOrIEntation) { case UIImageOrIEntationleft: case UIImageOrIEntationleftMirrored: case UIImageOrIEntationRight: case UIImageOrIEntationRightmirrored: // Grr... CGContextDrawImage(ctx,CGRectMake(0,self.size.wIDth),self.CGImage); break; default: CGContextDrawImage(ctx,self.size.height),self.CGImage); break;}// And Now we just create a new UIImage from the drawing contextCGImageRef cgimg = CGBitmapContextCreateImage(ctx);UIImage *img = [UIImage imageWithCGImage:cgimg];CGContextRelease(ctx);CGImageRelease(cgimg);return img;}@end
并在捕获图像保存期间调用此函数或从库中选择图像.
总结以上是内存溢出为你收集整理的iphone – imageOrientation返回Up,但照片显示颠倒全部内容,希望文章能够帮你解决iphone – imageOrientation返回Up,但照片显示颠倒所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)