views:

37

answers:

1

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.

+1  A: 

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.

Toro
the name of the image is coming from a database table. so if the name of the table is 'recipe', the field is called 'image' (recipe.image), how would that fit into the line of code you posted.it's the syntax that's confusing me. thanks
hanumanDev
thanks for your help
hanumanDev
this was the code I ended up using:CGRect myImageRect = CGRectMake(5.0f, 45.0f, 310.0f, 315.0f);UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];[myImage setImage:[UIImage imageNamed:recipe.image]];myImage.opaque = YES;
hanumanDev