UIImagePickerControllerEditedImage始终存在(UIImagePickerControllerEditedImage always present)

系统教程 行业动态 更新时间:2024-06-14 17:02:18
UIImagePickerControllerEditedImage始终存在(UIImagePickerControllerEditedImage always present)

当我从苹果文档中使用UIImagePickerController时,这段代码让我烦恼。 使用“if(editedImage)”检查图像是否已编辑的部分始终为真。 这是如此(根据本网站上的人的说法),因为当选择器设置为编辑YES时,即使未编辑图像,UIImagePickerControllerEditedImage也将始终具有数据。 问题是如果两者(UIImagePickerControllerEditedImage和UIImagePickerControllerOriginalImage)都变成非零,我们怎么知道哪个被选中?

我在这里和谷歌看了很多教程和许多其他问题。 但它回到了同样的事实,即使你没有编辑它,代码的逻辑也会使你编辑的图像100%。

我测试了这个代码以及其他问题中给出的其他代码,但问题始终保持不变,我无法分辨哪个是用户想要使用的代码。 如果字典具有BOOL值,那将非常有用。

在测试我的应用程序时,如果我从相册中选择一张照片或拍摄一张新照片,我会进入编辑屏幕,在那里我可以取消或接受并调整大小/裁剪图像。 即使我没有触摸图像,按下接受也会一直得到编辑过的图像。

以下是来自图像选择器的Apple文档API的代码。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType]; UIImage *originalImage, *editedImage, *imageToSave; // Handle a still image capture if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo) { editedImage = (UIImage *) [info objectForKey: UIImagePickerControllerEditedImage]; originalImage = (UIImage *) [info objectForKey: UIImagePickerControllerOriginalImage]; if (editedImage) { imageToSave = editedImage; } else { imageToSave = originalImage; } } // work with image or save and exit modal. }

this code is bugging me as I took this from the apple documentation for using the UIImagePickerController. The section where you check if the image was edited using the “if (editedImage)” always comes out true. This is so (as according to people on this site) as UIImagePickerControllerEditedImage will always have data even if image was not edited, when the picker is set to editing YES. The problem is how can we know which was selected if both (UIImagePickerControllerEditedImage and UIImagePickerControllerOriginalImage) turns out to be non-nil?

I looked thru many tutorials and many other question on here and Google. But it comes back to the same fact the logic of the code gets you the edited image 100% even if you have not edited it.

I tested this code and other codes that had been given in other questions but the problems always remains the same I can’t tell which one is the one the user want to use. It would really help if the dictionary had a BOOL value to know.

While testing my app if I choose a photo from the album or take a new one I am taken to the edit screen where I can cancel or accept and resize/crop the image. And pressing accept gets me the edited image all the time even if I have not touched the image.

Here is the code from apple documentation API for the image picker.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType]; UIImage *originalImage, *editedImage, *imageToSave; // Handle a still image capture if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo) { editedImage = (UIImage *) [info objectForKey: UIImagePickerControllerEditedImage]; originalImage = (UIImage *) [info objectForKey: UIImagePickerControllerOriginalImage]; if (editedImage) { imageToSave = editedImage; } else { imageToSave = originalImage; } } // work with image or save and exit modal. }

最满意答案

根据Wolvorin的回答结束问题:

这是它应该工作的方式,因为你已经将UIImagePickerController的编辑模式设置为true它会自动缩放图像并裁剪它,即使你没有触摸图像它只使用当前在正方形(白色边框)可见的图像。 所以你总是得到编辑的图像属性分配或说不是空--Wolvorin 1月30日8:32

closing question as per Wolvorin's answer:

This is the way it should work as you have set the editing mode of UIImagePickerController to true it automatically scales the image and crop it even if you do not touch the image it only use the image which is currently visible in square (white bordered). So you always get edited image property assigned or say not null – Wolvorin Jan 30 at 8:32

更多推荐

本文发布于:2023-04-21 18:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/cf5ecf05dab561d517c54bfb8293e32d.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:UIImagePickerControllerEditedImage   present

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!