Sqlite에 이미지를 저장하고 UIImageView에 이미지를로드하려고합니다. 그러나 그것은 효과가 없습니다. 나는 잘못되고있는 것이 아니다. 여기에 제가 사용하고있는 코드가 있습니다. 아무도 나를이 문제를 해결하는 데 도움이 될 수 있습니다.iOS에서 SQLite와의 이미지 저장 및 검색
- (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];
}
}
}
}
누구든지 위의 코드로 문제를 지적 할 수 있습니까? 사전에
감사
왜 대신 파일 시스템을 사용하지 않을까요? – Jake
offtopic : 앞으로의 프로젝트에서 FMDatabse를 사용해야합니다. https://github.com/ccgus/fmdb – CarlJ