数据库写入图片
很简单吧,在UIKit框架里有这个方法
[insertSql appendString:@") VALUES(?1)"];
sqlite3_stmt *insert_statement = nil;
sqlite3 *database = 你的数据库;
if (sqlite3_prepare_v2(database, [insertSql UTF8String], -1, &insert_statement, NULL) == SQLITE_OK) {
sqlite3_bind_blob(insert_statement, 1, [data bytes], [data length], NULL);
if(sqlite3_step(insert_statement) != SQLITE_DONE) {
NSLog(@"Db error %s", sqlite3_errmsg(database));
}
} else {
NSLog(@"Db error %s", sqlite3_errmsg(database));
}
sqlite3_finalize(insert_statement);
[insertSql release];
You need to use a BLOB (Binary Large OBject) if you want to store the actual image from that URL.
//Storage
UIImage*image =...;//Retrieve image from URL
NSData*imageData =UIImagePNGRepresentation(image);
sqlite3_bind_blob(compiledStatement,1,[imageData bytes],[imageData length], NULL);
//Retrieval
constvoid*data = sqlite3_column_blob(compiledStatement,1);
int length = sqlite3_column_bytes(compiledStatement,1);
UIImage*retrieved =[UIImage imageWithData:
[NSData dataWithBytes:data length:length]];