开发者

Conversion of Blob to UIImage from a Sqlite Database

I saved an image using Coredata in my application. Then i imported the Sqlite file in another projec开发者_StackOverflowt and retrieved that Blob field and converted to NSData. Then i got a NULL value when trying to convert this NSData to UIImage.

NSData *data=UIImageJPEGRepresentation(tempImage, 1.0);

saved the above data by saving context

To get back from Sqlite ::

const char *sqlStatement = "select ID,NAME,IMAGE from CALL";
sqlite3_stmt *compiledStatement;
NSData *data=[[NSData alloc] initWithBytes: sqlite3_column_blob(compiledStatement, 2) length:sqlite3_column_bytes(compiledStatement, 2)];
UIImage * showImage= [UIImage imageWithData: data];


The code you are writing is correct.

Difference I found in your code and some other code on internet is:

You use: UIImageJPEGRepresentation(tempImage, 1.0);

They use: UIImagePNGRepresentation(self.coffeeImage);

Though this is not the correct solution of your question but though It may help you to investigate further in issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜