lundi 2 mars 2015

Can't display image from sqlite database (blob) in iphone

I'm trying to display image from my sqlite database (as a blob), it knows that the image file is there by displaying the length of the image and the NSLog:"Image FOUND", but it doesn't load the image in the imageview. I've tried those many examples from stackoverflow like this one and more else but still no issue.Thanks in advance guys. Here is what I got so far:


sqlite3_stmt *statement1;



NSString *querySQL1 = [NSString stringWithFormat:@"SELECT picture FROM table1 WHERE var = %f", variable];

const char *query_statement1 = [querySQL1 UTF8String];

if(sqlite3_prepare_v2(_DB, query_statement1, -1, &statement1, nil) == SQLITE_OK)
{

if (sqlite3_step(statement1) == SQLITE_ROW)
{

int length = sqlite3_column_bytes(statement1, 0);

NSData *data = [[NSData alloc] initWithBytes:sqlite3_column_blob(statement1, 0) length:length];

UIImage *image = [UIImage imageWithData:data];

NSLog(@"Length : %d", [data length]);

if(data == nil)
{
NSLog(@"No image found.");
}

else
{
NSLog(@"image FOUND .");
myImageView.image = image;
}
}

}

Aucun commentaire:

Enregistrer un commentaire