2

我将图像作为 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 *'

谁能告诉我如何在单独的图像视图中显示这些图像。

提前致谢。

4

2 回答 2

0

[UIImage imagedNamed:xxx] 将从您的应用程序包中获取图像,xxx 是图像名称的字符串。尝试这个:

[bCardFront setImage:bgImage];
于 2012-05-02T04:16:40.120 回答
0

bCardFront.image=[UIImage imageNamed:bgImage]替换为

bCardFront.image=bgImage 这里 bgImage 不是图像名称它是 UIImage 的对象

于 2012-05-02T04:19:22.630 回答