如何检测iPhone相机是否没有拍摄图像?

时间:2014-02-04 17:36:10

标签: ios iphone uiimage

我目前正在使用imageOrientation的{​​{1}}属性来确定在相机拍摄照片后是否将照片翻转为横向照片:

UIImage

目前这适用于相机拍摄的照片,但我注意到,当涉及从网络下载的截图图片或图片时,无论图片是否真实地处于横向状态,默认方向始终设置为横向。

我的问题是:

  1. 有没有办法检测手机的相机是拍摄//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; } 还是来自相机设备?
  2. 有没有办法隐式确定UIImage是采用横向还是纵向?
  3. 谢谢!

1 个答案:

答案 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
}