Alpha channel not written to bmp by QImage::save?
-
Hello --
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:
#include <QGuiApplication>
#include <QDebug>
#include <QImage>
#include <QPixelFormat>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 = falseAm I doing something wrong on save?
Thanks for any info you can give.
-
-
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.
-
@SGaist
if i see correctly, the code for reading supports the BMP alpha channel, where as only the code for writing does not.
Maybe for a reason? idk -
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?
-
@shwoods said in Alpha channel not written to bmp by QImage::save?:
Did you ever get feedback on this?
no, since i never asked anyone :)
You can ask on the Qt mailing-list if you like.