Skip to content Skip to sidebar Skip to footer

Qt - Loading Image With Wrong Extension

I'm currently working on a Qt program that works with images that are supplied by the users. One problem I've run into is that a lot of images are saved with the wrong extension -

Solution 1:

I solved this by using a QImageReader. An example is shown below using PySide. First I created an instance of QImageReader and set it to read the format from the content.

image_reader = QtGui.QImageReader()
image_reader.setDecideFromContent(True)

This setting tells the reader to only look at the image's data to determine its format and not the extension.

Then I set the filename to the filename of the image I wanted to load and called read().

image_reader.setFileName(file_path_here)
image = image_reader.read()

Read returns a QImage object, so I proceeded with the rest of my code from there.

Post a Comment for "Qt - Loading Image With Wrong Extension"