Results 1 to 7 of 7

Thread: Grayscale image Color Conversion

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Nov 2007
    Posts
    55
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Grayscale image Color Conversion

    I am not sure wether I understood your request the right way. I am assuming that you want to convert all black pixels to full transparency and all other pixels to red.
    The first point is your loop which is not correctly initialized. Even if you initialized x and y outside the loop, latest when scanning the second column your variable y will be out of range, so the inner loop will be performed only once.

    Your loop should look like
    Qt Code:
    1. for ( x = 0; x < secondaryImage.width(); ++x )
    2. {
    3. for ( y = 0; y < secondaryImage.height(); ++y )
    4. {
    5. if ( secondaryImage.pixel( x, y ) == Qt::black )
    6. secondaryImage.setPixel( x, y, QColor( 0, 0, 0, 0 )); // fully transparency, color doesn´t matter
    7. else
    8. secondaryImage.setPixel( x, y, Qt::red );
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    I did not test the code!

  2. The following user says thank you to alainstgt for this useful post:

    2lights (12th August 2013)

Similar Threads

  1. Replies: 3
    Last Post: 14th August 2012, 14:47
  2. Image conversion black and white
    By offline in forum Qt Programming
    Replies: 1
    Last Post: 25th March 2010, 01:21
  3. image conversion speed?
    By tommy in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2008, 06:49
  4. can you save 8 bpp grayscale bitmaps?
    By eric in forum Qt Programming
    Replies: 3
    Last Post: 18th November 2007, 11:00
  5. conversion of color
    By Stephano in forum Qt Programming
    Replies: 5
    Last Post: 22nd May 2006, 11:56

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.