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?
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?
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::convertToFormat();
QImage:: pixelColor();
QImage::setPixelColor();
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.
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.
Bookmarks