2

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

ios
  • 6,134
  • 20
  • 71
  • 103

3 Answers3

1

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
aelam
  • 2,796
  • 2
  • 27
  • 32
0

Use NSKeyedArchiver How to convert NSArray to NSData?

Community
  • 1
  • 1
Andiih
  • 12,285
  • 10
  • 57
  • 88
  • Thanks for reply I Want to cobvert from NSArray to NSData Not from NSMutableArray so please let me know NSKeyedArchiver would help me – ios Jan 11 '11 at 13:33
  • the code if you follow those links http://lists.apple.com/archives/cocoa-dev/2002/Jan/msg00315.html is an extension of NSArray (not NSMutableArray) Have you tried it ? – Andiih Jan 12 '11 at 08:07
0
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

mrburns05
  • 11
  • 1