Results 1 to 4 of 4

Thread: QImage Restricted to 256 Pixels?

  1. #1
    Join Date
    Mar 2010
    Posts
    28
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QImage Restricted to 256 Pixels?

    Hey,

    I was just wondering about QImage if its only restricted to 256 pixels to be displayed and if there was another format I could use to correct QImage or another class similar to QImage I can use to create images through pixels.

    The following is the coding I used:
    Qt Code:
    1. QImage image (13,20, QImage::Format_Indexed8);
    2. QRgb value;
    3. value = qRgb (240,240,240);
    4. image.setColor (256, value);
    To copy to clipboard, switch view to plain text mode 

    The following error is what I receive when I attempt to assign 260 Pixels:

    QImage::setColor: Index out of bound 256
    QImage::setColor: Index out of bound 257
    QImage::setColor: Index out of bound 258
    QImage::setColor: Index out of bound 259
    QImage::setPixel: Index 257 out of range
    QImage::setPixel: Index 258 out of range
    QImage::setPixel: Index 259 out of range

    Thanks,
    Strateng
    Last edited by strateng; 1st April 2010 at 01:05.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage Restricted to 256 Pixels?

    From the docs -
    void QImage::setColor ( int index, QRgb colorValue )
    Sets the color at the given index in the color table, to the given to colorValue. The color value is an ARGB quadruplet.
    And since you have taken QImage::Format_Indexed8 format, I bet even 9 should give you an error ! (Am not sure though how index table works,, but you can check if am right or wrong )

  3. #3
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QImage Restricted to 256 Pixels?

    Format_indexed8 means you are using an 8bit *colortable* that may contain 256 colorvalues, thus counting from 0..255.

    When you do: setPixel(256, ...), or setColor(256, ...)
    you are asking for the color at location 256, which is beyond the maximum address.

  4. #4
    Join Date
    Mar 2010
    Posts
    28
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage Restricted to 256 Pixels?

    Quote Originally Posted by boudie View Post
    Format_indexed8 means you are using an 8bit *colortable* that may contain 256 colorvalues, thus counting from 0..255.

    When you do: setPixel(256, ...), or setColor(256, ...)
    you are asking for the color at location 256, which is beyond the maximum address.
    Thanks for the replies, but I was able to figure out a way to fix the problem I was having. I realised I was only limited by the number of colours and not limited by the number of pixels able to be displayed.

Similar Threads

  1. Replies: 16
    Last Post: 29th March 2010, 07:05
  2. best way of reading and writing QImage pixels?
    By billconan in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2010, 08:23
  3. Pixels
    By Dante in forum Qt Programming
    Replies: 1
    Last Post: 21st April 2009, 20:50
  4. How to change the values of the pixels in an Qimage?
    By kid17 in forum Qt Programming
    Replies: 8
    Last Post: 23rd November 2008, 20:52
  5. Convert RAW 8 bit pixels into a QImage
    By danielperaza in forum Qt Programming
    Replies: 3
    Last Post: 10th March 2008, 14:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.