开发者

how can we get image from local?

I store image in local by this code...

NSData *imageData = UIImagePNGRepresentation(image);
NSString *imageName = [NSString stringWithFormat:@"image.png"];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];

[imageData wri开发者_JS百科teToFile:fullPathToFile atomically:YES];

I can see this image in my iphone simulator bundle ...but how can i get back this image ?


If you mean recreate the image from a file, you can do that very simply by using UIImage's +imageWithContentsOfFile: method:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPathToFile = [documentsDirectory stringByAppendingPathComponent:@"someImageName"];
UIImage *image = [UIImage imageWithContentsOfFile:fullPathToFile];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜