Objective c 在不影响图像的情况下更改UIImage imageOrientation元数据
我有一个应用程序,它从本地磁盘加载一个图像,然后将其显示在UIImageView上。我想将图像设置为纵横比以适合 我遇到的问题是,imageOrientation返回为UIImageOrientationRight,即使它是一幅肖像图像,这会影响纵横比计算的方式 我尝试过几种改变元数据的方法,但都会在图像显示时旋转图像Objective c 在不影响图像的情况下更改UIImage imageOrientation元数据,objective-c,uiimage,Objective C,Uiimage,我有一个应用程序,它从本地磁盘加载一个图像,然后将其显示在UIImageView上。我想将图像设置为纵横比以适合 我遇到的问题是,imageOrientation返回为UIImageOrientationRight,即使它是一幅肖像图像,这会影响纵横比计算的方式 我尝试过几种改变元数据的方法,但都会在图像显示时旋转图像 UIImageView *iv = [[UIImageView alloc] initWithFrame:self.frame.frame]; NSMutableStri
UIImageView *iv = [[UIImageView alloc] initWithFrame:self.frame.frame];
NSMutableString *path =[[NSMutableString alloc] initWithString: [[NSBundle mainBundle] resourcePath]];
[path appendString:@"/pic2.jpg"];
NSData *data = [NSData dataWithContentsOfFile:path];
UIImage *img = [UIImage imageWithData:data];
UIImage *fixed1 = [UIImage imageWithCGImage:[img CGImage]
scale:1.0
orientation: UIImageOrientationUp];
UIImage *sourceImage = img;
UIImage *fixed2 = [UIImage
imageWithCGImage:[img imageRotatedByDegrees:90].CGImage
scale:sourceImage.scale
orientation:UIImageOrientationUp];
iv.image = fixed1; // fixed2;
[iv setContentMode:UIViewContentModeScaleAspectFill];
[self.view addSubview:iv];
最后,我采用了另一种方法,将UIImageView 360调宽,并将其放置在中心,从而达到了预期效果