0
我通過URL將圖像存儲到數據庫表中。即時通訊使用從URL獲取圖像後。我插入成功。具有URL路徑的圖像。但是,當提取它顯示二進制值<Mydata: 0x71756b0>
。這是什麼?僅顯示二進制值的圖像
代碼:
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
NSData* data = nil;
// UIImage *image = nil;
// const char *sql = "SELECT product_image FROM product order by order_by";
const char *sql = "SELECT product_image FROM product";
NSLog(@"sql is %s",sql);
sqlite3_stmt *statement;
// int catID = 0;
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
// We "step" through the results - once for each row.
while (sqlite3_step(statement) == SQLITE_ROW) {
Mydata *Mylist = [[Mydata alloc]init];
int length = sqlite3_column_bytes(statement, 2);
data = [NSData dataWithBytes:sqlite3_column_blob(statement, 2) length:length];
// UIImage *image = [UIImage imageWithData:data];
Mylist.photo = [[UIImage alloc] initWithData:data];
NSLog(@"my list is %@",Mylist);
[mArray addObject:Mylist];
}
}
sqlite3_finalize(statement);
}
else {
sqlite3_close(database);
NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));
// Additional error handling, as appropriate...
}
}
圖片顯示:
int Width = 0;
for (int i = 0; i<[mArray count]; i++) {
NSLog(@"index %@", mArray[i]);
imgView1=[[UIButton alloc]initWithFrame:CGRectMake(20+(i*74), 0, 72, 72)];
Width = Width + 20+(i*74);
[imgView1 setTag:i+1];
[imgView1 addTarget:self action:@selector(Clicked:) forControlEvents:UIControlEventTouchUpInside];
[imgView1 setImage:((Mydata *)[mArray objectAtIndex:i]).photo forState:UIControlStateNormal];
[scrollview addSubview:imgView1];
// [myScroll addSubview:imgView1];
}
你粘貼的代碼中沒有任何叫做「Mydata」的東西。 – Amar
對不起。從這一行檢查編輯的問題Mydata * Mylist = [[Mydata alloc] init]; – user2674668
您正在記錄正確顯示的實例的地址。究竟是什麼問題? – Amar