iPhone将图像从imageview存储到文件

ios*_*ios 8 sqlite iphone objective-c uiimageview uiimagepickercontroller

在我的iPhone应用程序中,我从iPhone图像库以及设备相机中选择图像,我在imageView中显示该图像.

我可以将我的图像存储到iPhone图像库中.

但是现在我想将我的图像存储在具有特定名称的某个目录中,因此我可以在我的应用程序中再次使用该图像,并且还希望将其存储在sqlite文件中.

the*_*ent 9

这里有一个简短的写法: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];
Run Code Online (Sandbox Code Playgroud)

要将它存储在SQLite数据库中,您将获取生成NSData对象的代码(UIImageJPEGRepresentation或者UIImagePNGRepresentation)并将它们保存到BLOB列.