在我以前的应用程序中,数据是从光盘读取的,如下所示:
NSData* image = [NSData dataWithContentsOfFile:pngImage];
我将所有.png
数据移动到BLOB
数据库中的SQLite
数据库
FMDatabase *database = [FMDatabase databaseWithPath:pathToDatabase];
[database open];
NSString *sqlSelectQuery = @"SELECT ....";
FMResultSet *resultFromDatabase = [database executeQuery:sqlSelectQuery];
如何将数据库中的返回值(BLOB
)转换为NSData
对象?
答案 0 :(得分:0)
FMDB为此提供method:
NSData *image = [databaseResult dataForColumn:@"image_column"];
答案 1 :(得分:-2)
您可以将BLOB转换为NSData:
NSMutableData *data = [NSMutableData dataWithCapacity:blobs.count];
for (NSNumber *number in blobs)
{
uint8_t byte = (uint8_t)[number intValue];
[data appendBytes:&byte length:1];
}