我想在SQL数据库中保存显示的UIImageview图像。我正在使用UIImageview中显示的相机/相册/库来捕捉图像。我想使用URL将此图像保存在我的SQL数据库中。
另外,我需要在另一个视图中显示此图像。
如何获取我的imageview图像的路径(URL)?如何存储此路径(URL)&还存储&显示到另一个视图?
答案 0 :(得分:1)
如何获取UIImage并写入内部目录:
UIImageView *imageView = "[your image]";
// define your own path and storage for image
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [paths objectAtIndex:0];
documentPath = [documentPath stringByAppendingPathComponent:@"test.jpg"];
NSData *imageData = UIImageJPEGRepresentation(imageView.image, 1.0);
[imageData writeToFile:documentPath atomically:YES];
如何在内部目录中获取文件路径的NSURL / NSString:
// specify fileURL as it is an internal file, don't use URLWithString:
NSURL *fileURL = [NSURL fileURLWithPath:documentDirectory];
// store as a string in database
NSString *fileURLString = fileURL.path;
请注意,本地文件的NSURL与普通的NSURL不同。
// for normal URL
NSURL *webURL = [NSURL URLWithString:"http://www.google.com/"];
[webURL absoluteString]; // -> http://www.google.com/
// for local file path URL
NSURL *localURL = [NSURL fileURLWithPath:"/User/path/samplefile.ext"];
[localURL absoluteString]; // -> file://User/path/samplefile.ext
[localURL path]; // -> /User/path/samplefile.ext
答案 1 :(得分:0)
只需将您的图片名称保存在数据库中并将图像存储在手机内存中...这将很容易或以这种方式尝试此行
UIImage *img = [UIImage imageWithContentsOfFile:(the file path)];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];