Joe Cannatti
Joe Cannatti

Reputation: 5089

Finding a UIImage file type

Is there a way to determine what file type was used to create a UIImage?

Upvotes: 2

Views: 1456

Answers (3)

nurider
nurider

Reputation: 1843

If the image is add using the imagePickerController you can determine the type in your image picker delegate method as follows:

- (void)imagePickerController:(UIImagePickerController *)picker 
didFinishPickingMediaWithInfo:(NSDictionary *)info {

    // Get the image reference URL
    NSURL *referenceURL = [info objectForKey:UIImagePickerControllerReferenceURL];

    // The path extension contains the image type: JPG, PNG, GIF, etc.
    NSString *originalImageType = referenceURL.pathExtension; 

}

Upvotes: 0

jpm
jpm

Reputation: 16712

Does it really matter what type the original image was? Can you implement whatever you want by inspecting the details of the underlying CGImageRef object (property is called CGImage) for alpha component information, etc?

For more details lookup the documentation for CGImage from the UIImage manual page.

Upvotes: 3

Andrew Grant
Andrew Grant

Reputation: 58804

Nope!

If this is for images you've loaded yourself you could store that association somewhere else instead. If the file is from elsewhere then it may not even have come from a file in the first place.

Upvotes: 2

Related Questions