如何检查,从UIImagePickerController
中选择的图像是否为全景图像?
答案 0 :(得分:1)
在这个UIImagePickerController
委托方法中(确保将委托方法添加到View Controller类中):
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self dismissViewControllerAnimated:YES completion:NULL];
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// determine if it's panorama by checking its dimension
CGFloat imageWidth = image.size.width;
CGFloat imageHeight = image.size.height;
// display the image if needed
[self.imageView setImage:image];
self.imagePickerController = nil;
}
理论上,全景图像的宽度比普通图像长得多。但这无法检查它是否是从其他地方下载的网络图像。
答案 1 :(得分:0)
Swift 3.0
根据上述建议,我们可以检查全景图像的宽度,因此我们可以忽略大幅图像
正常图像信息“尺寸{960,960}方向1比例1.000000”
全景图片信息“尺寸{13632,2936}方向1比例1.000000”
let str = "\(info["UIImagePickerControllerOriginalImage"]!)"
let s = str.slice(from: "{", to: "}")
if let arr = s?.components(separatedBy: ","){
if arr.count >= 2 {
if Int(arr[0])! > 11000 {
picker.dismiss(animated:true, completion: nil)
self.makeToast("Invalid Image!!!")
return
}
if Int(arr[1])! > 11000 {
picker.dismiss(animated:true, completion: nil)
self.makeToast("Invalid Image!!!")
return
}
}
}