Results 1 to 7 of 7

Thread: Filling an image

  1. #1
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Filling an image

    file.h:
    Qt Code:
    1. QImage background;
    To copy to clipboard, switch view to plain text mode 

    file.cxx:
    Qt Code:
    1. this->background = QImage(size, QImage::Format_RGB32);
    2. this->background.fill(Qt::black);
    3. std::vector<double>::const_iterator it = values.begin();
    4. for (int j=0 ; j<this->original_size[1] ; j++)
    5. for (int i=0 ; i<this->original_size[0] ; i++,it++)
    6. if (*it >= 1)
    7. for (int ii=0 ; ii<factor ; ii++)
    8. for (int jj=0 ; jj<factor ; jj++)
    9. this->background.setPixel(i*factor+ii, j*factor+jj, Qt::green);
    10. int g=0, b=0;
    11. for (int j=0 ; j<background.height() ; j++)
    12. for (int i=0 ; i<background.width() ; i++)
    13. if (background.pixel(i,j) == Qt::black)
    14. b++;
    15. else if (background.pixel(i,j) == Qt::green)
    16. g++;
    17. printf("%d black pixels and %d green pixels\n", b, g);
    To copy to clipboard, switch view to plain text mode 

    Expected result: some green pixels among black ones (I checked there really are some points for which *it == 1)
    Actual result: 0 0 !

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Filling an image

    Qt::black and Qt::green are values of enum Qt::GlobalColor. The value of Qt::black is 2 and Qt::green is 8. Comparing these values to the values of image pixels doesn't make sense to me...
    J-P Nurmi

  3. #3
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Filling an image

    Quote Originally Posted by jpn View Post
    Qt::black and Qt::green are values of enum Qt::GlobalColor. The value of Qt::black is 2 and Qt::green is 8. Comparing these values to the values of image pixels doesn't make sense to me...
    Ok, it is no doubt for me that you are right Guru, but beyond that could you ALSO help me solving the problem?

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Filling an image

    What is
    Qt Code:
    1. background.setPixel(i*factor+ii, j*factor+jj, Qt::green);
    To copy to clipboard, switch view to plain text mode 
    supposed to do? Remember that Qt::green is not an RGB value but an enum value.
    J-P Nurmi

  5. #5
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Filling an image

    Ok, I have solved the problem, I need to explicitely give the ARGB values, ie 0xff00ff00 for green. I just believed that there was a way to get it as a constant for classic colors, as with Qt::green and so.

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Filling an image

    Quote Originally Posted by Caius Aérobus View Post
    Ok, I have solved the problem, I need to explicitely give the ARGB values, ie 0xff00ff00 for green. I just believed that there was a way to get it as a constant for classic colors, as with Qt::green and so.
    It's still an enum value. To get an RGB value you would do something like:
    Qt Code:
    1. QRgb rgb = QColor(Qt::green).rgb();
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  7. #7
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Filling an image

    Quote Originally Posted by jpn View Post
    It's still an enum value. To get an RGB value you would do something like:
    Qt Code:
    1. QRgb rgb = QColor(Qt::green).rgb();
    To copy to clipboard, switch view to plain text mode 
    Not an enum but a constant, and finally easier than the above solution lol

Similar Threads

  1. Finding marks on scanned image for alignment
    By caduel in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2007, 02:10
  2. Help needed handling image data
    By toratora in forum General Programming
    Replies: 2
    Last Post: 11th May 2007, 09:24
  3. how i can add image in my toolbar
    By jyoti in forum Qt Tools
    Replies: 7
    Last Post: 19th December 2006, 14:39
  4. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36
  5. Question about updating an image on screen
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2006, 19: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.