Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QImage returns wrong bytesPerLine for 8-bit indexed image
Forum Updated to NodeBB v4.3 + New Features

QImage returns wrong bytesPerLine for 8-bit indexed image

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 537 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Thrr
    wrote on last edited by Thrr
    #1

    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
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • T Offline
        T Offline
        Thrr
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • T Offline
          T Offline
          Thrr
          wrote on last edited by
          #4

          I think I got it wrong, using "bytesPerLine" and "sizeInBytes" is more accurate than width() and height() when loading from raw data.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved