Does there exist a better way to do it than this?
void setAlphaChannel(QPixmap& pixmap, int const alpha)
{
QImage image
(pixmap.
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(alpha);
image.setPixel(x, y, color.rgba());
}
}
pixmap
= QPixmap::fromImage(image
);
}
void setAlphaChannel(QPixmap& pixmap, int const alpha)
{
QImage image(pixmap.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(alpha);
image.setPixel(x, y, color.rgba());
}
}
pixmap = QPixmap::fromImage(image);
}
To copy to clipboard, switch view to plain text mode
I've read about the now-obsolete QPixmap method called setAlphaChannel(), but it's implementations are platform-dependent.
Bookmarks