1

I want to save displayed UIImageview image in SQL database. I am capturing the image using the camera/albums/library which are displayed in UIImageview. I want to save this image in my SQL database using URL.

Also I need to display this image in another view.

How can I take a path(URL) of my imageview image? How can I store this path(URL) & also store & display into another view?

4

2 回答 2

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
于 2013-06-30T12:04:43.737 回答
0

只需将图像的名称保存在数据库中并将图像存储在手机内存中......这很容易,或者这样试试这条线

UIImage *img = [UIImage imageWithContentsOfFile:(the file path)];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
于 2013-06-30T15:09:00.863 回答