开发者

How to save aUIImage using NSUserDefaults

开发者 https://www.devze.com 2022-12-13 22:43 出处:网络
How 开发者_如何学JAVAdo I save an Image to User DefaultsYou can save it as NSData. To get a NSData object from a UIImage, you can use one of the following functions:

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

精彩评论

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