在我的iPhone应用程序中,我从iPhone图像库以及设备相机 中选取图像,并在imageView中显示该图像。iPhone将图像从图像存储到文件
我能够将我的图像存储到iPhone图像库。
但是现在我想将我的图像存储在某个具有特定名称的目录中,因此我可以在我的应用程序中再次使用该图像,并且还希望将其存储在sqlite文件中。
在我的iPhone应用程序中,我从iPhone图像库以及设备相机 中选取图像,并在imageView中显示该图像。iPhone将图像从图像存储到文件
我能够将我的图像存储到iPhone图像库。
但是现在我想将我的图像存储在某个具有特定名称的目录中,因此我可以在我的应用程序中再次使用该图像,并且还希望将其存储在sqlite文件中。
有这样一个简短的书面记录在这里:http://iosdevelopertips.com/data-file-management/save-uiimage-object-as-a-png-or-jpeg-file.html
这里是直接从该网站窃取相关代码:
// Create paths to output images
NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.png"];
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"];
// Write a UIImage to JPEG with minimum compression (best quality)
// The value 'image' must be a UIImage object
// The value '1.0' represents image compression quality as value from 0.0 to 1.0
[UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];
// Write image to PNG
[UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];
将其存储在一个SQLite数据库,你会采取使代码NSData对象(UIImageJPEGRepresentation
或UIImagePNGRepresentation
)并将它们保存到BLOB列。
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/ImageFileName.jpg"];
[UIImageJPEGRepresentation(yourUIImageView.image,1.0) writeToFile:path atomically:YES];
如果你正在处理的PNG有一个名为UIImagePNGRepresentation另一种方法。
iphonesdkarticles.com已经死了,robots.txt禁止archive.org抓取它。 – 2017-07-01 05:06:53