我通过 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];
}