2009-12-15 57 views

回答

2

您可以将其保存为NSData。 从一个UIImage得到一个NSData对象,你可以使用下列功能之一:

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

而打开的NSData回的图像,你可以使用imageWithData或initWithData

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

但也许把它写到不同的文件是一个更好的主意。

+0

好吧那我怎么写TI的临时文件夹,如果我要覆盖然后我怎么做,也做怎样,我读了文件回来? 谢谢你的代码btw。 – Jaba

+0

可以保存的NSData用的将writeToFile方法 的NSData *数据= UIImagePNGRepresentation(图像)之一; 的NSArray *路径= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString * documentsDirectory = [paths objectAtIndex:0]; NSString * filePath = [documentsDirectory stringByAppendingPathComponent:@“file.png”]; [data writeToFile:filePath atomically:YES]; –

+0

谢谢你这么玉米粥这有助于我得到我想要 – Jaba