Results 1 to 3 of 3

Thread: Greyscale png with transparency

  1. #1
    Join Date
    Aug 2011

    Default Greyscale png with transparency

    I have an image I create that is normalized to 8-bit (0->255) stored as quint8*. I pass this to QImage and it works well. Is there anyway to set the black pixels to transparent without using libpng to set the tRNS?

  2. #2
    Join Date
    Mar 2011
    Hyderabad, India
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    MacOS X Unix/X11 Windows
    Wiki edits

    Default Re: Greyscale png with transparency

    Convert the QImage to one of the formats which support alpha channel (example QImage::Format_ARGB32) , then set the black color pixels with alpha color.

    Read about
    QImage:: pixelColor();
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Aug 2011

    Default Re: Greyscale png with transparency

    So after I make the QImage in greyscale, convert to ARGB, set the pixels to transparent, and then back to greyscale? There isn't a more efficient method?

    I have that working properly but only when the image is saved as ARGB. I want to keep it in Format_Grayscale8 when creating the PNG. No reason to use 4x the memory.

    Added after 8 minutes:

    If anyone wants the solution, none of this is necessary. If you want a value to be transparent in an 8-bit grayscale QImage that will be saved to a PNG, there is not anyway to do that inheritely in Qt it seems. You need to manually add the tRNS header and value to the PNG header.
    Last edited by Chops211; 10th May 2018 at 15:27.

Similar Threads

  1. 8bit greyscale raw picture find painted area
    By dazedly in forum Qt Programming
    Replies: 1
    Last Post: 17th April 2012, 09:00
  2. Save greyscale image
    By Lele in forum Qt Programming
    Replies: 8
    Last Post: 12th August 2008, 08:59
  3. QImage-Greyscale-8-bits-pixel
    By Ivan Labrador in forum Newbie
    Replies: 5
    Last Post: 3rd August 2008, 00:08
  4. Painter greyscale, image quality paint-brush!
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 22nd March 2007, 20:32
  5. transparency
    By roms18 in forum Qt Programming
    Replies: 2
    Last Post: 16th February 2006, 19:38

Tags for this Thread


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.