将图像从资产库复制到应用程序文件夹 [英] Copy image from assets-library to an app folder

查看:66
本文介绍了将图像从资产库复制到应用程序文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIImagePickerController,我想将选定的图像保存到我的应用程序中.我可以通过获取当前的 UIImage 并保存它(通过创建文件)来轻松做到这一点,但我更愿意直接将文件从 Library 复制到我的文件夹.所以现在我有一个所选图像的 URL:UIImagePickerControllerReferenceURL,它返回一个特定的模式assets-library".我试图将图像从这种 URL 复制到路径,但没有成功.

I have an UIImagePickerController and I would like to save a selected image to my app. I can do that easy by getting the current UIImage and save it (by creating a file) but I would prefer to directly copy the file from Library to my folder. So now I have an URL of the selected image : UIImagePickerControllerReferenceURL which return a specific pattern "assets-library". I tried to copy an image from this kind of URL to a path but without success.

有没有办法让我想做的事情取得成功?谢谢!

Is there a way to success on what I would like to do ? Thanks !

推荐答案

可以通过两种方式来解决

You can do it through two ways

第一种方式:使用 imagePickerController didFinishPickingMediaWithInfo 委托

First Way: Using imagePickerController didFinishPickingMediaWithInfo delegate

-  (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

     UIImage *selectedImage = [info valueForKey:UIImagePickerControllerOriginalImage];

    //save selectedImage to document directory      

 }

第二种方式:使用ALAssetLibrary.

为此,您必须保存ALAsset URL 并使用ALAssetLibrary 检索图像,请参阅我的详细回答 .只需输入您的 ALAsset url 而不是 asseturl

For this you have to save the ALAsset URL and retrieve the image using ALAssetLibrary, please refer my answer for details .Just put your ALAsset url instead of asseturl

这篇关于将图像从资产库复制到应用程序文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆