我有一个应用程序,它从本地磁盘加载图像,然后将其显示在UIImageView上。我想将图像设置为宽高比例以适应。
我遇到的问题是imageOrientation以UIImageOrientationRight的形式返回,即使它是一个肖像图像,并且弄乱了方面计算的方式。
我尝试了一些更改元数据的方法,但是在显示时都会旋转图像。
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];
答案 0 :(得分:0)
最后,我采用了不同的方法,使UIImageView 360变宽并将其置于中心,从而达到了预期的效果。