gpt4 book ai didi

ios - SQLite 保存和加载图像 iOS

转载 作者:行者123 更新时间:2023-11-28 22:46:33 25 4
gpt4 key购买 nike

我正在尝试保存图像并将其加载到 tableView 中,以便保存在我的 SQLite 文件中我这样做:

-(void)InsertRecords:(NSData *)pic{
..... // Open my SQLite file
NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO myMovies (movieImage) VALUES (\"%@\")", pic];
...
const char *insert_stmt = [insertSQL UTF8String];
...
sqlite3_bind_blob(statement, 1, [pic bytes], [pic length], NULL);
...

哪张图片是 NSData,我得到了它的 NSLog。并给了我代码。同样为了加载我使用了这段代码:

int length = sqlite3_column_bytes(sqlStatement, 1);
MyMovie.image = [NSData dataWithBytes:sqlite3_column_blob(sqlStatement, 1) length:length];

和 NSLoged 来自它,它具有与 NSData 相似的结构,但数据不同!彻底变了!难道我做错了什么 ?

最佳答案

sqlite3_bind_blob 绑定(bind)到一个参数,但是你的插入语句实际上没有参数。 (您应该检查它的返回值是否有错误。)

您插入的语句是将图片格式化为字符串,它会因任何非 ASCII 字节而中断。

关于ios - SQLite 保存和加载图像 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13091483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com