Alpha channel not written to bmp by QImage::save?
-
wrote on 18 Jan 2018, 01:11 last edited by
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.
-
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.
@shwoods
hi,
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. -
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.
-
wrote on 18 Jan 2018, 12:17 last edited by
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.
-
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 -
wrote on 18 Jan 2018, 15:30 last edited by
Thank you both! I will take a look at the code and see what it would take to change it.
-
@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? idkwrote on 29 Jan 2018, 13:28 last edited byI 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?
-
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.