QImageReader could not find the size of images
-
Hi,
UsingQt 6.9
onWindows 11 23H2
, I found that QImageReader couldn't work properly on some formats, especially in getting the pictures' size info. In particular, I testedbmp
,png
,jpg
formats, and found that QImageReader would only give me the right info of thejpg
formatted pictures. For example, the following code:QImageReader imgReader; imgReader.setFileName("..."); imgReader.setAutoTransform(true); if (imgReader.canRead()) { QMessageBox::warning(nullptr, "...", QString::number(imgReader.size().width()), QMessageBox::Close); }
will tell me the correct width of a
jpg
image, while only-1
of pictures in other formats.
Surprisingly, if I then read a pixmap from thatQImageReader
, use the getters from thatQPixmap
, and I would see all the correct info.QPixmap pixmap{ QPixmap::fromImageReader(&imgReader) }; QMessageBox::warning(nullptr, "...", QString::number(pixmap.width()), QMessageBox::Close);
The result above is always right.
Also, I've tested thesupportsOption
function:imgReader.supportsOption(QImageIOHandler::Size);
It's always
true
.
Why is it? It's so strange that I think I may look for help. Thanks. -
Hi,
I have not checked the code of these readers but from a quick look at the QImagrReader::size documentation they might fall in the category of "needs to be fully read to get that information".
-
Qt's built-in image handlers all support this feature
I was just confused by that sentence. Formats like
BMP
are built in, but their size cannot be determined until they are fully read... Doesn't theBITMAPINFOHEADER
contain useful information about its width and height? -
The BMP handler should give that information unless something wrong happened when reading the file header.
Can you provide a minimal compilable example with a sample images that would allow to check what happens ?
-
And create a bug report and notify me so I can take a look on it after holidays. I would expect that the size is always returned correctly, no matter if we have to read the whole file or not. I know it is working for png and assume it must work for others in QIconloader class so it is important to see if there is something wrong.
-
I think I have learnt sth. For handlers like
BMP
, we cannot do reading operations before callingsize()
. If I callsize()
immediately aftercanRead()
, the result is correct; if I have calledread()
or sth likeQPixmap::fromImageReader()
before the call tosize()
, the result is invalid. However for theJPG
handler, there's no such restriction. -
Please create a bug report
-