开发者

Conversion of Blob to UIImage from a Sqlite Database

开发者 https://www.devze.com 2023-03-09 07:32 出处:网络
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

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

精彩评论

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

关注公众号