开发者

How to save aUIImage using NSUserDefaults

How 开发者_如何学JAVAdo I save an Image to User Defaults


You can save it as NSData. To get a NSData object from a UIImage, you can use one of the following functions:

NSData * UIImagePNGRepresentation (UIImage *image);
NSData * UIImageJPEGRepresentation (UIImage *image);

And to turn the NSData back into an image, you can use imageWithData or initWithData

UIImage * a = [[UIImage alloc] initWithData:data];
UIImage * b = [UIImage imageWithData:data];

But maybe it's a better idea to write it to a different file.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜