Does iOS support UIImage formats other than JPEG and PNG?

I notice that in Apple's documentation on UIImage there are only two functions for converting uiimage objects to data objects - one for the jpeg format and one for the png format. Does that mean that iOS does not support any other image formats? I need to know because I need to save uiimage objects using FileManager, which requires them be saved as Data objects.

Accepted Reply

This thread has been deleted

The docs say 'it is recommended' - if you're faced with outlier formats in that example, you can either proceed and take your chances on usage compatibility post-save, or check the file type to see if it isn't jpg/png and decline the process....or...offer to convert.

Replies

iOS supports other image file types ( see Table C-2 here: https://developer.apple.com/library/archive/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/LoadingImages/LoadingImages.html#//apple_ref/doc/uid/TP40010156-CH17-SW7 )....but the docs say this about that:


"Although image objects support all platform-native image formats, it is recommended that you use PNG or JPEG files for most images in your app. Image objects are optimized for reading and displaying both formats, and those formats offer better performance than most other image formats. Because the PNG format is lossless, it is especially recommended for the images you use in your app’s interface."



Example below if you need it...


Note In iOS, 'home directory' is the application’s sandbox directory.


// Create paths to output images
NSString  *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.png"];
NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"];

// Write a UIImage to JPEG with minimum compression (best quality)
// The value 'image' must be a UIImage object
// The value '1.0' represents image compression quality as value from 0.0 to 1.0
[UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];

// Write image to PNG
[UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];

// Let's check to see if files were successfully written...

// Create file manager
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
// Point to Document directory
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
  
// Write out the contents of home directory to console
NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);