iPhone:如何获取使用UIImageWriteToSavedPhotosAlbum()保存的图像的文件路径? [英] iPhone: How do I get the file path of an image saved with UIImageWriteToSavedPhotosAlbum()?

查看:2583
本文介绍了iPhone:如何获取使用UIImageWriteToSavedPhotosAlbum()保存的图像的文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下方法将合并后的图片保存到iPhone照片库:

  UIImageWriteToSavedPhotosAlbum(viewImage,self,@ selector( savedPhotoImage:didFinishSavingWithError:contextInfo :),nil); 

使用以下方式获取回调:

   - (void)savedPhotoImage:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {NSLog(@%@,[error localizedDescription]); 
NSLog(@info:%@,contextInfo);}

我想做什么喜欢得到的是图像保存位置的路径,所以我可以将它添加到一个数组中,该数组将用于调用应用程序中其他位置的已保存项目列表。



当我使用选择器加载图像时,它会显示路径信息。
但是当我保存创建的图像时,我无法找到保存图像路径的位置。



我搜索了网络,但大多数示例停止回调,发送一条好消息说图像已成功保存。
我只想知道它的保存位置。



我理解一种方法可能是开始定义我自己的路径,但作为方法这对我来说,我只是希望它可以告诉我它保存到哪里。

解决方案

我终于找到了答案。
显然UIImage方法剥离了元数据,所以使用UIImageWriteToSavedPhotosAlbum是不行的。



然而在ios4中Apple放入了一个新的框架来处理名为的照片库ALAssetsLibrary。



首先,您需要右键单击Targets,然后在构建部分中,使用左下角的小+图标将AlAsset Framework添加到项目中。 / p>

然后将 #importAssetsLibrary / AssetsLibrary.h; 添加到班级的头文件中。



最后你可以使用以下代码:

  UIImage * viewImage =你的UIIMAGE // ---我的是由绘图上下文组成的
ALAssetsLibrary * library = [[ALAssetsLibrary alloc] init];
//请求将图像保存到相机胶卷
[library writeImageToSavedPhotosAlbum:[viewImage CGImage] orientation:(ALAssetOrientation)[viewImage imageOrientation] completionBlock:^(NSURL * assetURL,NSError * error){
if(error){
NSLog(@error);
} else {
NSLog(@url%@,assetURL);
}
}];
[图书馆发布];

这将获得刚刚保存的文件的路径。


I'm saving a merged image to the iPhone photo library using:

UIImageWriteToSavedPhotosAlbum(viewImage, self, @selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), nil);

And getting the callback using:

- (void) savedPhotoImage:(UIImage*)image didFinishSavingWithError:(NSError *)error contextInfo: (void *)contextInfo { NSLog(@"%@", [error localizedDescription]);
NSLog(@"info: %@", contextInfo);}

What I would like to get is the path for where the image has been saved, so I can add it to an array which will be used to call up a list of saved items elsewhere in the app.

When I load the image using the picker it displays the path info. However when I save a created image, I can't find where to pull the saved image path.

I have search about the web, but most examples stop at the callback with a nice message to say the image was saved successfully. I would just like to be able to know where it was saved.

I understand one method might be to start defining my own paths, but as the method does that for me, I was just hoping it could tell me where it saved to.

解决方案

I finally found out the answer. Apparently the UIImage methods strip out metadata and so using UIImageWriteToSavedPhotosAlbum is no good.

However in ios4 Apple put in a new framework to handle the photo library called the ALAssetsLibrary.

First you need to right click on the Targets and in the build part, add the AlAsset Framework to your project with the little + icon in the bottom left.

Then add #import "AssetsLibrary/AssetsLibrary.h"; to the header file of your class.

Finally you can use the following code:

UIImage *viewImage = YOUR UIIMAGE  // --- mine was made from drawing context
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];  
// Request to save the image to camera roll  
[library writeImageToSavedPhotosAlbum:[viewImage CGImage] orientation:(ALAssetOrientation)[viewImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){  
    if (error) {  
        NSLog(@"error");  
    } else {  
            NSLog(@"url %@", assetURL);  
    }  
}];  
[library release];

And that gets the path of the file you just saved.

这篇关于iPhone:如何获取使用UIImageWriteToSavedPhotosAlbum()保存的图像的文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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