0

What are the image file formats supported by UIImage?

I managed to find this documentation page but is is quite old and outdated I assume since it does not even include PDF.

https://developer.apple.com/library/archive/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/LoadingImages/LoadingImages.html#//apple_ref/doc/uid/TP40010156-CH17-SW7

banderson
  • 65
  • 1
  • 11

1 Answers1

1

Actually the UIImage itself should have no direct correlation to formats you are looking for and you will need to add more context. UIImage is just a representation of raw pixel data such as 32bit RGBA.

A more contextual question would be; what are supported formats to initialize UIImage by using init(contentsOfFile:) method which is described here. Unfortunately even this part seems to lack documentation for what formats it supports though.

In parent documentation I can only see mentioning of PNG and JPEG formats. And trying to initialize it with a pdf actually results as a fail and returns nil.

But then on the other hand pdf is supported in assets which is a completely different thing. Quickly inspecting web I can find no proper documentation from Apple about it (Though I assume it must be somewhere) but there is this very nice post about it you should read. Basically it states that PDFs are actually converted to PNGs at build time.

So perhaps the information you posted is not outdated at all.

Matic Oblak
  • 16,318
  • 3
  • 24
  • 43
  • Thank you for answer. There is a flag in inspector when you choose the PDF resource: "Preserve Vector Data". I don't know how it is handled but it is not converted to PNG at build time if you enable that. – banderson Sep 23 '20 at 14:38