用 iPhone 的sqlite数据库读写图片,先把你的图片转换成 NSData 形式,然后在数据库添加一行 blob 数据,代码如下(data就是图片) :
NSMutableString *insertsql = [[NSMutableString alloc] initWithString:@"INSERT INTO "]; [insertsql appendString:BLOB]; [insertsql appendString:@" ("]; [insertsql appendString:BLOB_DATA]; [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];
转自:http://blog.knowsky.com/193441.htm 原文链接:https://www.f2er.com/sqlite/200776.html