我目前正在使用imageOrientation
的{{1}}属性来确定在相机拍摄照片后是否将照片翻转为横向照片:
UIImage
目前这适用于相机拍摄的照片,但我注意到,当涉及从网络下载的截图图片或图片时,无论图片是否真实地处于横向状态,默认方向始终设置为横向。
我的问题是:
//3 is upright
//2 is upside-down
//1 is button on the left
//0 is button on the right
if (self.imageTakenOrSelected.imageOrientation == 1){ //Taken landscape with button the left
UIImage *flippedImage = [UIImage imageWithCGImage:self.imageTakenOrSelected.CGImage scale:self.imageTakenOrSelected.scale orientation:UIImageOrientationRight];
self.imageTakenOrSelected = flippedImage;
} else if (self.imageTakenOrSelected.imageOrientation == 0){ //Taken landscape with button the right
UIImage *flippedImage = [UIImage imageWithCGImage:self.imageTakenOrSelected.CGImage scale:self.imageTakenOrSelected.scale orientation:UIImageOrientationRight];
self.imageTakenOrSelected = flippedImage;
}
还是来自相机设备?谢谢!
答案 0 :(得分:3)
对于#1,使用this solution获取与UIImage关联的EXIF字典。那里有很多钥匙可以识别相机。
#2
只是比较图像的宽度和高度
CGFloat width = [image width];
CGFloat height = [image height];
if (width > height) {
// image is landscape
} else {
// image is portrait
}