1

I'm making a photo managing app. I have created a class called photo, which has the name of the photo, notes on the photo, and the image. I know how to set the name and notes - they're both NSStrings, but what data type should I use for my image?

At the moment, I'm using NSData, is that correct?


Edit

Apparently, NSData is right. So, how should I get an image from a UIImage into the NSData object and back again?

Todd Davies
  • 5,484
  • 8
  • 47
  • 71

3 Answers3

3

Data from UIImage:

NSData *imageData = UIImagePNGRepresentation(image);

Alternatively, UIImage from data:

UIImage *image = [UIImage imageWithData:imageData];
Stavash
  • 14,244
  • 5
  • 52
  • 80
1

You can store your image as an UIImage or NSData

You can simply get one from another:

NSData *data = UIImagePNGRepresentation(image);
UIImage *image=[UIImage imageWithData:data];
0

In case you need the image for presenting it's better practice to hold an UIImage instance in youre object transferring it to/from NSData when you need to save it or get it either from the net or the disk. If youre case is more like file manager then photo viewer, then this answer is not aplicable. Anyway the transfering routines were provided to you by previous answer.

Ariel
  • 2,430
  • 1
  • 17
  • 20