hanumanDev
hanumanDev

Reputation: 6614

displaying an image from sqlite table

I was storing an image in a sqlite table as blob data and displaying it using the following code:

self.myImage.image = [[[UIImage alloc] initWithData:recipe.image] autorelease];

I'm now using the image file name in the sqlite fields instead and storing the image on the filesystem. what would the code be to display it that way? I'm having a hard time figuring it out.

normally to display an image from the filesystem I'd use: UIImage *image = [UIImage imageNamed:@"something.png"];

in this case I have to grab the string that's in the table field/attribute.

thanks in advance.

Upvotes: 0

Views: 449

Answers (1)

AechoLiu
AechoLiu

Reputation: 18378

You can load UIImage with absolute filepath by following API.

+ (UIImage *)imageWithContentsOfFile:(NSString *)path;

+(UIImage *)imageNamed:(NSString *)name will look for an image from application's main bundle. In other word, it will look for an image from Resources.

Editted:

You said that you stored the image on the filesystem. So, I think you can retrive the absolute filepath of image from sqlite database, doesn't it?

NSString *imgPath; 

/// get imgPath from sqlite database
...

/// get the image by filepath
self.myImage.image = [UIImage imageWithContentOfFile:imgPath];

And, my question is how do you store the image on the filesystem.

Upvotes: 1

Related Questions