@Spitfire's code works good for flat images.
If your image has varying alpha values you can use:
QImage tmp
= pixmap.
toImage();
for(int y = 0; y < tmp.height(); y++)
for(int x= 0; x < tmp.width(); x++)
color.setAlpha(tmp.pixelColor(x,y).alpha());
tmp.setPixelColor(x,y,color);
QImage tmp = pixmap.toImage();
for(int y = 0; y < tmp.height(); y++)
for(int x= 0; x < tmp.width(); x++)
color.setAlpha(tmp.pixelColor(x,y).alpha());
tmp.setPixelColor(x,y,color);
pixmap = QPixmap::fromImage(tmp);
To copy to clipboard, switch view to plain text mode
Commented:
// "pixmap" is your QPixmap
// "color" is your QColor
// Convert the pixmap to QImage
QImage tmp
= pixmap.
toImage();
// Loop all the pixels
for(int y = 0; y < tmp.height(); y++)
{
for(int x= 0; x < tmp.width(); x++)
{
// Read the alpha value each pixel, keeping the RGB values of your color
color.setAlpha(tmp.pixelColor(x,y).alpha());
// Apply the pixel color
tmp.setPixelColor(x,y,color);
}
}
// Get the coloured pixmap
// "pixmap" is your QPixmap
// "color" is your QColor
// Convert the pixmap to QImage
QImage tmp = pixmap.toImage();
// Loop all the pixels
for(int y = 0; y < tmp.height(); y++)
{
for(int x= 0; x < tmp.width(); x++)
{
// Read the alpha value each pixel, keeping the RGB values of your color
color.setAlpha(tmp.pixelColor(x,y).alpha());
// Apply the pixel color
tmp.setPixelColor(x,y,color);
}
}
// Get the coloured pixmap
pixmap = QPixmap::fromImage(tmp);
To copy to clipboard, switch view to plain text mode
Bookmarks