sqlite中写入图片二进制数据及读取源码 for iphone

sqlite中写入图片二进制数据及读取源码 for iphone,第1张

概述写入: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *dataPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@”sqlite.sqlite”]; NS

写入:

NSArray *paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES);

Nsstring *dataPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@”sqlite.sqlite”];

NSData *image=UIImagePNGRepresentation([UIImage imagenamed:@"01_02.png"]);
Nsstring *aaa=[[Nsstring alloc]initWithFormat:@”update cards set c_image=? where ID=1″];

sqlite3 *database;

if (sqlite3_open([dataPath UTF8String],&database) == sqlITE_OK){
sqlite3_stmt * complIEdStatement;
sqlite3_prepare(database,[aaa UTF8String],-1,&complIEdStatement,0);
sqlite3_bind_blob(complIEdStatement,1,[image bytes],[image length],NulL);
int result=sqlite3_step(complIEdStatement);
if (result==sqlITE_DONE) {
}
sqlite3_finalize(complIEdStatement);

}
sqlite3_close(database);
[aaa release];

读取:

NSArray *paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,YES);
Nsstring *dataPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@”sqlite.sqlite”];
sqlite3 *database;
if (sqlite3_open([dataPath UTF8String],&database) == sqlITE_OK){
const char *sqlStatement=”select c_image from cards where ID=1″;
sqlite3_stmt *complIEdStatement;
if(sqlite3_prepare(database,sqlStatement,NulL)==sqlITE_OK)
{
while (sqlite3_step(complIEdStatement)==sqlITE_ROW) {
int bytes = sqlite3_column_bytes(complIEdStatement,0);
const voID *value = sqlite3_column_blob(complIEdStatement,0);
if( value != NulL && bytes != 0 ){
NSData *data = [NSData dataWithBytes:value length:bytes];
UIImage *image=[UIImage imageWithData:data];
[imageVIEw setimage:image];

}
else{

} } } sqlite3_finalize(complIEdStatement); } sqlite3_close(database);

总结

以上是内存溢出为你收集整理的sqlite中写入图片二进制数据及读取源码 for iphone全部内容,希望文章能够帮你解决sqlite中写入图片二进制数据及读取源码 for iphone所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1182429.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存