Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何检测图像是否不是由iPhone摄像头拍摄的?_Ios_Iphone_Uiimage - Fatal编程技术网

Ios 如何检测图像是否不是由iPhone摄像头拍摄的?

Ios 如何检测图像是否不是由iPhone摄像头拍摄的?,ios,iphone,uiimage,Ios,Iphone,Uiimage,我目前正在使用UIImage的imageOrientation属性来确定在相机拍摄照片后是否将照片翻转到横向: //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
imageOrientation
属性来确定在相机拍摄照片后是否将照片翻转到横向:

//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;
    }
目前,这对相机拍摄的照片很好,但我注意到,当涉及到截屏图片或从web下载的图片时,默认方向总是设置为横向,不管图片是否真正处于横向

我的问题是:

  • 是否有方法检测图像是由手机摄像头拍摄还是来自内置设备
  • 是否有一种方法可以隐式确定UIImage是横向拍摄还是纵向拍摄 谢谢

    对于#1,使用获取与UIImage关联的EXIF字典。那里有很多识别相机的钥匙

    对于#2

    只需比较图像的宽度和高度

    CGFloat width  = [image width];
    CGFloat height = [image height];
    
    if (width > height) {
      // image is landscape
    } else {
      // image is portrait
    }
    

    考虑查看EXIF信息(IMAIO框架)