简体   繁体   中英

How to retrieve image from sqlite database in iPhone App

In my iPhone App I want to retrieve image from (stored in ) sqlite database table in "BLOB" datafield.

For that I am storing my image in NSData using code

NSData *imageData = UIImagePNGRepresentation(image);

and I am also able to retrieve image from NSData -> UIImage by code

self.img1=[UIImage imageWithData:imageData];

And displaying Image into imageView by

imageView2.image=img1;

I am storing image (in NSData form) into sqlite database table column (of BLOB Datatype) successfully.

I am using below code to retrieve image from database

NSData *imageData2 = [[arraySelect objectAtIndex:0] valueForKey:@"image_column"];   
NSLog(@"imagedata2 in retrive :: %@",imageData2);

in NSLOG i am getting the same data stored in database column (in blob datatype "NSData form" )

Now I am retrieving image by (while debugging it crashes here and showing meaasge EXE_BAD_ACCESS)

self.img3=[UIImage imageWithData:imageData2];
imageview3.image=img3;

But I am not getting that image in imageView. I checked all outlets but they are ok.

So please Help and Suggest what I should do to get image in imageView from database.

Thanks.

@Prera​​k我认为这将为您提供帮助。并解决您的问题http://dblog.com.au/iphone-development-tutorials/iphone-sdk-tutorial-reading-data-from-a-sqlite-database/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM