我正在尝试将图像保存到 Sqlite,然后将图像加载到 UIImageView。但它没有得到工作。我不知道出了什么问题。这是我正在使用的代码。谁能帮我解决这个问题。
- (void)saveImage {
sqlite3_stmt *compiledStmt;
if(sqlite3_open([dbPath UTF8String], &db)==SQLITE_OK){
const char *insertSQL="insert into Image(Image)values(?)";
if(sqlite3_prepare_v2(db,insertSQL, -1, &compiledStmt, NULL) == SQLITE_OK){
UIImage *image = [UIImage imageNamed:@"farmhouse.png"];
NSData *imageData=UIImagePNGRepresentation(image);
sqlite3_bind_blob(compiledStmt, 1, [imageData bytes], [imageData length], NULL);
sqlite3_step(compiledStmt);
char *errMsg;
sqlite3_exec(db, insertSQL, NULL,compiledStmt,&errMsg);
}
}
}
- (void)showImage {
sqlite3_stmt *compiledStmt;
if(sqlite3_open([dbPath UTF8String], &db)==SQLITE_OK){
const char *insertSQL = "Select Image from Image Where Sl.No = ?";
sqlite3_prepare_v2(db,insertSQL, -1, &compiledStmt, NULL);
if(sqlite3_prepare_v2(db,insertSQL, -1, &compiledStmt, NULL) == SQLITE_OK){
sqlite3_bind_int(compiledStmt, 1, 1);
if(SQLITE_DONE != sqlite3_step(compiledStmt)) {
NSData *data = [[NSData alloc] initWithBytes:sqlite3_column_blob(compiledStmt, 1) length:sqlite3_column_bytes(compiledStmt, 1)];
if(data == nil)
NSLog(@"No image found.");
else
imgView.image = [UIImage imageWithData:data];
}
}
}
}
谁能指出上面代码的问题。
提前致谢