问题描述
我有一个UIImagePickerController
,允许用户从图像库中选择一个图像,并通过didFinishPickingMediaWithInfo
方法获得其结果.
I've got a UIImagePickerController
letting the user pick an image out of the image library, and am getting its results via the didFinishPickingMediaWithInfo
method.
我需要能够将生成的图像保存到磁盘(在应用程序的documents文件夹中),并在以后重新加载.
I need to be able to save the resulting image to disk (in the app's documents folder), and reload it later.
问题是我不知道是否将其存储为PNG或JPEG.我不能总是将其存储为PNG,因为对于较大的照片,它的运行速度非常慢(更不用说我必须单独存储图像方向).我不能总是将其存储为JPEG,因为在某些情况下图像具有透明度,如果这样做会丢失.
The issue is that I can't tell whether to store it as a PNG or JPEG. I can't just always store it as a PNG, because for larger photos it's interminably slow (not to mention then I have to deal with storing the image orientation separately). I can't just always store it as a JPEG, because in some cases the images have transparency, which will get lost if I do that.
我已经检查了图像选择器返回的信息词典中的UIImagePickerControllerMediaType
键,无论选择了PNG还是JPEG,返回的都是"image.public"
.
I've examined the UIImagePickerControllerMediaType
key in the info dictionary returned by the image picker, and regardless of whether I've selected a PNG or JPEG, what gets returned is "image.public"
.
所以...
是否可以通过某种方式知道用户是否选择了PNG?也许只是一些方法来检查图像是否具有透明度或其他功能?
Is there some way to know whether the user has chosen a PNG? Maybe some method of just checking if the image has any transparency or something?
谢谢.
推荐答案
在字典中,键UIImagePickerControllerReferenceURL将为您提供有关类型的信息
in the dictionary the key UIImagePickerControllerReferenceURL will give you informations about the type
(gdb)订单信息
{
UIImagePickerControllerMediaType = "public.image";
UIImagePickerControllerOriginalImage = "<UIImage: 0x5cfd00>";
UIImagePickerControllerReferenceURL = "assets-library://asset/asset.JPG?id=EFC44C3C-9C82-4669-924B-A2B9DE6F1F45&ext=JPG";
}
在这种情况下,它是ext = JPG所示的jpg
In this case it is a jpg as shown by ext=JPG
这篇关于使用UIImagePickerController获取图像-如何知道是否保存PNG或JPEG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!