iPhone 使用 AlAssetLibrary 自动将照片与我们的应用程序同步

发布于 2024-11-01 00:49:44 字数 284 浏览 0 评论 0原文

我刚刚开始开发一个应用程序,我想在其中自动同步存储在用户照片库中的所有图像作为资产。

我能够获取作为资产存储的图像的 URL。

e.g. assets-library://asset/asset.JPG?id=1000000003&ext=JPG

现在,如何将此图像复制到应用程序的文档目录中,或者如何通过在 NSDataUIImage 中获取存储在资产中的图像来显示该图像?

提前致谢。

I have just started developing an application in which I want to auto sync all the images stored in user's photo library as assets.

I am able to get URL for images those are stored as assets.

e.g. assets-library://asset/asset.JPG?id=1000000003&ext=JPG

Now, how do I copy this image in to document's directory of my application or how do I just display image stored in assets by getting that in NSData or in UIImage?

Thanks in Advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余厌 2024-11-08 00:49:44

您可以在 UIImagePickerControllerDelegate 委托实现中使用以下代码

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

    //obtaining saving path
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:@"my_photo.png"];

    //extracting image from the picker and saving it
    UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
    NSData *imageData = UIImagePNGRepresentation(editedImage);
    [imageData writeToFile:imagePath atomically:YES];

}

You can use the following code in UIImagePickerControllerDelegate delegate implementation

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

    //obtaining saving path
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:@"my_photo.png"];

    //extracting image from the picker and saving it
    UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
    NSData *imageData = UIImagePNGRepresentation(editedImage);
    [imageData writeToFile:imagePath atomically:YES];

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文