开发者

How to Convert data obtained from Sqlite database into NSArray to NSData in iPhone SDK

开发者 https://www.devze.com 2023-02-03 20:22 出处:网络
In My iPhone App, I am converting my image in to NSData 开发者_开发知识库format and storing it into sqlite database Table in dataType=\"BLOB\",

In My iPhone App,

I am converting my image in to NSData 开发者_开发知识库format and storing it into sqlite database Table in dataType="BLOB",

But, I am retriving that image (stored in NSData format) into NSArray Format from database,

The Problem is I am not able to convert NSArray to NSData ( Which would Help me to get my image back into NSData format )

Please Help and Suggest, Thanks


Your requirement is so odd.

  1. you can store image in local file system with the file name in sqlite
  2. if you really want images store in sqlite, you can every image in sqlite separately rather than archive images in NSArray than convert to NSData


Use NSKeyedArchiver How to convert NSArray to NSData?


UIImage *imgData = [UIImage imageWithData:[yourArray objectAtIndex:theIndex]];

for multiple images in one array you can loop it

like

for (int i = 0;i<[yourArray count];i++) {
      UIImage *img = [UIImage imageWithData:[yourArray objectAtIndex:i];
      //do something here with each image
      // for example, add it to an ImageView
}

P.S. if theres only one image, its index is 0 hope this helps

0

精彩评论

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

关注公众号