Results 1 to 3 of 3

Thread: Problem with pixelIndex in QImage

  1. #1
    Join Date
    Sep 2009
    Posts
    31
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem with pixelIndex in QImage

    I do not understand this problem.
    I normally use a QImage, but now this happening a problem that I can not see.

    In my .h:
    Qt Code:
    1. QImage *mascara; // Máscara para filtro
    To copy to clipboard, switch view to plain text mode 

    In my .cpp:
    Qt Code:
    1. mascara = new QImage(2,2,QImage::Format_Indexed8);
    2.  
    3. mascara->setPixel(0,0,5);
    4. mascara->setPixel(0,1,5);
    5. mascara->setPixel(1,0,5);
    6. mascara->setPixel(1,1,5);
    7. QString test;
    8. test.setNum(mascara->pixelIndex(0,0));
    9. ui->console->appendPlainText(test);
    To copy to clipboard, switch view to plain text mode 

    I do not see the pixel that I placed. In test no have the value 5.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Problem with pixelIndex in QImage

    I guess its because you forgot to set a color table. In the used image format, pixel value is an index in color table, which you have to set before specifying pixel values.
    Something like this will work:
    Qt Code:
    1. QImage img(2,2,QImage::Format_Indexed8);
    2. img.setColor(0,5);
    3. img.setColor(1,3);
    4. img.setPixel(0,0,0);
    5. img.setPixel(0,1,1);
    6. qDebug() << img.pixel(0,0); // prints 5
    7. qDebug() << img.pixel(0,1); // prints 3
    To copy to clipboard, switch view to plain text mode 
    Its explained in docs with more details : link

  3. The following user says thank you to stampede for this useful post:

    danilodsp (17th September 2011)

  4. #3
    Join Date
    Sep 2009
    Posts
    31
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with pixelIndex in QImage

    Thank you very much!

Similar Threads

  1. Problem with displaying a QPixmap on a QImage
    By moatilliatta in forum Newbie
    Replies: 3
    Last Post: 7th September 2010, 17:30
  2. qImage saving to jpg problem
    By sqarpi in forum Qt Programming
    Replies: 9
    Last Post: 1st September 2010, 15:43
  3. QImage::pixelIndex out of range warning
    By danics in forum Qt Programming
    Replies: 1
    Last Post: 10th March 2010, 12:54
  4. QImage problem in Windows-2000
    By sabeesh in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd January 2008, 09:21
  5. RGBComponents / QImage Conversion problem
    By sincnarf in forum Qt Programming
    Replies: 2
    Last Post: 30th July 2007, 23:41

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.