QImage returns wrong bytesPerLine for 8-bit indexed image
-
wrote on 4 Jun 2020, 18:18 last edited by Thrr 6 Apr 2020, 18:25
The following code returns wrong number of bytes per line, since it's an 8 bit image, isn't the width supposed to be equal to the bytesPerLine?
It does not happen with all dimensions, but only certain ones.int www = 311; int hhh = 107; QImage nwImg = QImage( dt, www, hhh, QImage::Format_Indexed8 ); const int bpl = nwImg.bytesPerLine(); qDebug() << bpl; qDebug() << www; qDebug() << hhh;
Output
312 311 107
-
@Thrr said in QImage returns wrong bytesPerLine for 8-bit indexed image:
isn't the width supposed to be equal to the bytesPerLine?
Where is this written in the Qt documentation?
It's aligned on a 4 (or 8, don't remember and can't find it atm) byte boundary for performance reasons. This is imo also true für e.g. native windows bitmaps. -
wrote on 4 Jun 2020, 18:40 last edited byThis post is deleted!
-
wrote on 4 Jun 2020, 19:05 last edited by
I think I got it wrong, using "bytesPerLine" and "sizeInBytes" is more accurate than width() and height() when loading from raw data.
1/4