Opacity of a QImage becomes black
-
I have the same problem. Code without set opacity
QImage image = m_GemsPixmap.copy(p.kind*49, 0, 49, 49).toImage().convertToFormat(QImage::Format_ARGB32); // for (int x(0); x != image.width(); ++x) // { // for (int y(0); y != image.height(); ++y) // { // QColor color(image.pixel(x,y)); // color.setAlpha(p.alpha); // image.setPixel(x, y, color.rgba()); // } // } m_pixmapItems[i][j].setPixmap(QPixmap::fromImage(image));
Result
Code with control opacicty.QImage image = m_GemsPixmap.copy(p.kind*49, 0, 49, 49).toImage().convertToFormat(QImage::Format_ARGB32); for (int x(0); x != image.width(); ++x) { for (int y(0); y != image.height(); ++y) { QColor color(image.pixel(x,y)); color.setAlpha(p.alpha); image.setPixel(x, y, color.rgba()); } } m_pixmapItems[i][j].setPixmap(QPixmap::fromImage(image));
Result:
Transparent area is always black but for other opacity work correctly.
Do you know how solve that? -
Hi,
Do you mean that you need alpha to be at least 1 in order to have proper transparency handling ?