how to know this image is jpg or png iphone

Desmond picture Desmond · Apr 20, 2012 · Viewed 9.3k times · Source

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 UIImageJPEGRepresentation or UIImagePNGRepresentation so i could convert it.

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

Answer

Perception picture Perception · Apr 20, 2012

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.