我将图像作为BLOB存储在数据库中,然后使用以下编码
获取它const char*dbPath=[databasePath UTF8String];
if (sqlite3_open(dbPath, &sqliteHandler)==SQLITE_OK) {
sqlite3_stmt *stmt;
NSString *selctQuery=[NSString stringWithFormat:@"select * from imagetable where imageId=11"];
NSLog(@"selectQuery is %@",selctQuery);
const char *dispStmt=[selctQuery UTF8String];
sqlite3_prepare_v2(sqliteHandler, dispStmt, -1, &stmt, NULL);
NSLog(@"%d",sqlite3_prepare_v2(sqliteHandler, dispStmt, -1, &stmt, NULL));
while (sqlite3_step(stmt)==SQLITE_ROW) {
// NSString *pwd=[[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(sqltmt, 1)];
// NSString *image1=[[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(stmt, 1)];
// NSString *image2=[[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(stmt, 2)];
// NSString *image3=[[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(stmt, 3)];
//NSLog(@"%@",image1);
NSData *cachedImage1 = [[NSData alloc] initWithBytes:sqlite3_column_blob(stmt, 1) length: sqlite3_column_bytes(stmt, 1)];
NSData *cachedImage2 = [[NSData alloc] initWithBytes:sqlite3_column_blob(stmt, 2) length: sqlite3_column_bytes(stmt, 2)];
NSData *cachedImage3 = [[NSData alloc] initWithBytes:sqlite3_column_blob(stmt, 3) length: sqlite3_column_bytes(stmt, 3)];
thumbImage = [UIImage imageWithData:cachedImage1];
bgImage = [UIImage imageWithData:cachedImage2];
logoImage = [UIImage imageWithData:cachedImage3];
[cachedImage1 release];
[cachedImage2 release];
[cachedImage3 release];
}
}
我尝试使用以下代码显示...
bCardFront.image=[UIImage imageNamed:bgImage]
但它会发出警告信息
不兼容的Objective-C类型'struct UIImage *',当从不同的Objective-C类型传递'imageNamed:'的参数1时,预期'struct NSString *'
任何人都可以告诉我如何在单独的图像视图中显示这些图像。
提前致谢。
答案 0 :(得分:0)
[UIImage imagedNamed:xxx]将从您的应用包中获取图像,xxx是图像名称的字符串。试试这个:
[bCardFront setImage:bgImage];
答案 1 :(得分:0)
bCardFront.image=[UIImage imageNamed:bgImage]
替换为
bCardFront.image=bgImage
这里bgImage不是图像名称,它是UIImage的对象