I'm working on an app and I need to get bytes from an UIImage
.
For the moment, I use UIImagePickerController
, and get the UIImage
like this,
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
and then get data from UIImage
using this code,
NSData *data = UIImageJPEGRepresentation(image, 1.0);
However, data
appears to get corrupted in this case.
On other hand, I have add the jpeg to app's bundle, and tried to convert the image then to data,
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"mapa" ofType:@"jpeg"];
NSData *myData = [NSData dataWithContentsOfFile:filePath];
Surprisingly this works perfectly.
Here are my questions:
- How can I get the bytes of image selected from
UIImagePickerController
correctly?
- Is there a way to add photos to the bundle programmatically?
Thanks!
EDIT:
I have some metadata bytes on the original JPEG ("GEO-Information").
If i store the jpeg on the ipad, that metadata disappear, and I need them :S