Qt drawing icons using color and alpha-map -
I want to attract an icon (only one color) in different colors. To do this, I would like to import an alpha-texture and then add it to a given color in the application.
The result should be, nothing should be drawn on the background, when alpha-map 0 is ambiguous and the used color should be pulled, when the opacity is 1.
A soul should be hidden somewhere in Is anyone's idea? Thanks in advance EDIT: Here is a small graphic that I want to do. I want to use the alpha-map shown in the graphic and then I want to use a color layer to create my icon. Important, the background remains transparent. < Div class = "post-text" itemprop = "text"> For example: QPainter , because you can set the composition-mode (
QPainter :: setCompositionMode ) manually. But I do not like to do this work as if I want to.
Destination in these composition mode will trick.
sourceover .
DestinationIn Compose mode.
// https://github.com/KubaO/stackoverflown/tree/master/questions/alpha-mask-24943711 #include & lt; QtWidgets & gt; QImage icon (integer size) {QImage image {size, size, QImage :: Format_ARGB32_Premultiplied}; Image.fill (qt :: transparent); Copenerator p (& image); P.setRenderHint (QPainter :: Antialiasing); P.setPen (QT :: NoPen); (. Image.rect () center ()) p.translate; P.scale (image.width () / 2.2, image.height () / 2.2); P.setBrush (QT :: white); P.drawEllipse (QRectF {- 5, -5, 1., 1.}); P.setCompositionMode (QPainter :: CompositionMode_DestinationIn); P.setBrush (Qt :: transparent); P.drawEllipse (QRectF {- 3, -3 ,.6, .6}); (For auto angle: {0., 100., 150.}) {p.save (); P.rotate (angle); P.drawRect (QRectF {- 1, 0, 2. 2, -1}}; p.restore ();} Return Image;} Cumase Checkers {Cum Size} (Size * 2, Size * 2, QMJs :: Format_arbb 32_Premultiplied}; Copernor P (& amp; img); P.fillRect (0, 0, size, size, QT :: darkgray); P.fillRect (size, size, size, 2 * size, QT :: P.fillRect (size, 0, size, size, QT :: light gray); P.fillRect (0, size, size, size, QT :: light gray); return IMG;} zero draw colorful mark (couponer and P, Q Color color, contrast cum and alpha) {p.save (); p.setCompositionMode (QPainter :: CompositionMode_SourceOver); P.fillRect (QRect {0, 0, alpha.width (), alpha. ()}, Color); P.setCompositionMode (QPainter :: CompositionMode_DestinationIn); P.drawImage (0, 0, alpha); p.restore ();} QImage Draw ColorIconProof (QColor color, const QImage and alpha) {QImage Results {alpha.size ()), Alpha format ()}; coupter p (and results); attracted colored icons (p, color, alpha); p.setCompositionMode (QPainter :: CompositionMode_DestinationAtop); P.fillRect (alpha), {checkers (10)}); Return result; } Int main (int argc, char * argv []) {QApplication app {argc, argv}; QLabel label; Label.setPixmap (QPixmap :: fromImage (drawColorIconProof ("orange", symbol (200)))); Label.show (); Return app.exec (); }
Comments
Post a Comment