Solved Alpha channel not written to bmp by QImage::save?
Simple question, I hope. If I am using a QImage format that includes alpha, is QImage capable of writing it to a bmp with the alpha?
For instance, given the following program:
int main(int argc, char *argv)
QGuiApplication a(argc, argv);
QImage internal(50,50, QImage::Format_ARGB32); bool internal_has_alpha = internal.hasAlphaChannel(); internal.save("Saved.bmp"); QImage saved_bitmap("Saved.bmp", "BMP"); bool saved_has_alpha = saved_bitmap.hasAlphaChannel(); qDebug() << "internal alpha = " << internal_has_alpha; qDebug() << "saved alpha = " << saved_has_alpha; return 0;
The output is:
internal alpha = true
saved alpha = false
Am I doing something wrong on save?
Thanks for any info you can give.
I'm not sure, what the inner workings of QImage::save are, however alphachannel support seams not to be supported for bmp-saves. But, if you change your format from bmp to png, it should work.
I believe what you say is true -- that earlier bmp headers by definition did not support the alpha channel, but as I understand it, newer BMP headers (BITMAPV4HEADER and later) support alpha channel. Is it safe to say that QImage uses the older headers, which do not support alpha, and just convert it to RGB on save?
You are correct that png works fine -- I just need the later header on a bmp for the system I am working with. I can work around this, I am just curious as to whether I am just missing the command to generate the later headers.
Hi and welcome to devnet,
AFAIK, you didn't miss anything. You can take a look at the qbmphandler.cpp for the details of bitmap creation. If you'd like to, you can consider adding the support for alpha channel there.
Thank you both! I will take a look at the code and see what it would take to change it.
I was checking the code today and had the same question as you -- was there a particular reason alpha was left off on writing? Did you ever get feedback on this?