views:

85

answers:

1

I have some image data stored in BLOB format in MySQL database, I fetch the string and integer data but for image it does not display. i also tried using a UIImageView but it doesn't work.

Can some one please post some code to display the image data in a UITableView. NSData-->UIImage-->image display.

Thanks

A: 

Given a NSData object data where the data is a UIImage supported image type (PNG, JPG, ...)

/* These two are what I assume you start with */
char *rawData = [self getRawDataFromDB];
int rawDataLength = [self getLengthOfRawData];

/* To convert that to an image... */
UIImage *image = [UIImage imageWithData:[NSData dataWithBytes:rawData length:rawDataLength]];

Once you have the image, then add to your UITableViewDataSource's tableView:cellForRowAtIndexPath:

[[cell imageView] setImage: image];
John Franklin
after database fetching in resulti didfor(NSDictionary *row in result){ [tableData addObject:[row objectForKey:@"imgdata"]];}and in the table view method[cell.imageView setImage:[tableData objectAtIndex:index]];where to place your code can you Explain
xcodemaddy
You could put it in either place, but you need to convert the [row objectForKey:@"imgdata"] (which is the rawData) to a UIImage. I'd put it in the database fetch routine as [tableData addObject:image].
John Franklin
Thanks for ur reply.how to convert rawdata to get image??can you explain with piece of coding...
xcodemaddy