如何从Swift中的UIImagePickerController获取编辑过的图像?

问题描述:

我已经看过并阅读 Apple的文档,他们清楚地提到了关键 UIImagePickerControllerEditedImage 。但是当我运行以下代码时,我没有在字典中获得该密钥。这背后的原因是什么?

I have seen and read the documents of Apple where they have clearly mentioned about the key UIImagePickerControllerEditedImage. But when I am running my following code, I am not getting that key in the Dictionary. What is the reason behind this?

我的代码:

func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info:NSDictionary!)
    {
        println(info)

        //var tempImage:UIImage = info[UIImagePickerControllerOriginalImage] as UIImage
        var tempImage:UIImage? = info[UIImagePickerControllerEditedImage] as? UIImage

        profileButton.setImage(tempImage, forState: UIControlState(0))

        self.dismissViewControllerAnimated(true, completion:nil)

    }

println(info)打印:

println(info) prints:

{
    UIImagePickerControllerMediaType = "public.image";
    UIImagePickerControllerOriginalImage = "<UIImage: 0x178295d60> size {960, 960} orientation 0 scale 1.000000";
    UIImagePickerControllerReferenceURL = "assets-library://asset/asset.JPG?id=2DDCE06B-6082-4167-A631-B3DF627055DF&ext=JPG";
}

仅供参考,我从图书馆挑选图像,我也尝试使用相机,但是这个密钥仍然没有出现,但关于图像的其他数据即将到来。我正在使用iOS8.0构建SDK。

FYI, I am picking image from Library and I tried from Camera also, but this key is still not coming but the other data about image is coming. And I am using iOS8.0 build SDK.

那么我怎样才能使用 UIImagePickerControllerEditedImage 如果有的话没有这样的密钥进入字典。

So how can I use UIImagePickerControllerEditedImageif there is no such key coming in the dictionary.

你可以这样做。

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {

    let image = info[UIImagePickerControllerEditedImage] as UIImage
}