Desmond Desmond - 7 months ago 35
iOS Question

how to know this image is jpg or png iphone

i will like to pick an images from UIImagepicker, there are PNG and JPG format in camera roll.

and i need to convert it into NSData. However i need to know if this images is

so i could convert it.

UIImage *orginalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:nil];
NSData *orgData = UIImagePNGRepresentation(orginalImage);


You shouldn't know or care what the internal representation of images in the camera roll is. The methods you mentioned UIImageJPEGRepresentation and UIImagePNGRepresentation return you representations of the camera roll image. It's up to you to pick which representation you want to use.

To summarize:

NSData * pngData = UIImagePNGRepresentation(originalImage);

Will return you the image representation in an NSData object, with the format PNG.