Results 1 to 9 of 9

Thread: How to change the values of the pixels in an Qimage?

  1. #1
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    2

    Default How to change the values of the pixels in an Qimage?

    I read an image with:
    Qt Code:
    1. QString fileName = QFileDialog::getOpenFileName(this,
    2. tr("Open File"), QDir::currentPath());
    3. if (!fileName.isEmpty()) {
    4. QImage image(fileName);
    5.  
    6. imageLabel->setPixmap(QPixmap::fromImage(image));
    7. scaleFactor = 1.0;
    8.  
    9. printAct->setEnabled(true);
    10. fitToWindowAct->setEnabled(true);
    11. updateActions();
    12.  
    13. if (!fitToWindowAct->isChecked())
    14. imageLabel->adjustSize();
    15. }
    To copy to clipboard, switch view to plain text mode 
    Now I want to change the values of the pixels of this image with new values. They are contained in an matrix[][] of int representing the same image equalized with my function.
    The range of values in this matrix is 0-255.
    I tried with:
    Qt Code:
    1. for( int i = 0; i < r; i++ )
    2. for(int j = 0; j < c; j++)
    3. image.setPixel(j,i,(uint)matrix[i][j]);
    To copy to clipboard, switch view to plain text mode 
    but don't work, infact if I try to view it, I get a white image
    Hepl me!!Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to change the values of the pixels in an Qimage?

    What is the format of the image?

  3. #3
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    2

    Default Re: How to change the values of the pixels in an Qimage?

    the format is TIF.It is grayscale

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to change the values of the pixels in an Qimage?

    So it's probably not 24b. In that case the image uses a colour table - setPixel only determines which index of the colour table describes the colour of the image. The actual colour needs to be placed into the colour table. See QImage docs for details.

  5. #5
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    2

    Default Re: How to change the values of the pixels in an Qimage?

    I show docs but i don't understand how solved my problem

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to change the values of the pixels in an Qimage?

    See QImage::colorTable(), QImage::setColorTable and QImage "Image Formats" and "Pixel Manipulation" sections.

  7. #7
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    2

    Default Re: How to change the values of the pixels in an Qimage?

    I don't understand how I can change each pixel with the new. If I change the color table at position 1from x to y,each pixel 1 will be represented by y. Mistake?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to change the values of the pixels in an Qimage?

    Please read the docs where there is a table and code showing how to modify an 8bit image.

  9. The following user says thank you to wysota for this useful post:

    kid17 (24th November 2008)

  10. #9
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    2

    Default Re: How to change the values of the pixels in an Qimage?

    Quote Originally Posted by wysota View Post
    Please read the docs where there is a table and code showing how to modify an 8bit image.
    Thanks.I solved my problem.

Similar Threads

  1. Convert RAW 8 bit pixels into a QImage
    By danielperaza in forum Qt Programming
    Replies: 3
    Last Post: 10th March 2008, 14:53
  2. QSqlTableModel cannot change values
    By raphaelf in forum Newbie
    Replies: 2
    Last Post: 23rd May 2007, 08:01

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.