Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt 如何仅对具有非零alpha的区域着色/高亮显示qpixmap_Qt_Qpainter - Fatal编程技术网

Qt 如何仅对具有非零alpha的区域着色/高亮显示qpixmap

Qt 如何仅对具有非零alpha的区域着色/高亮显示qpixmap,qt,qpainter,Qt,Qpainter,我有一个QPixmap,它有一些透明区域。如何将高光/色调仅应用于具有非零alpha的区域 这就是我现在所拥有的,它为整个图像着色 QPixmap highlighedPixmap = myPixmap; QPainter pixmapPainter; pixmapPainter.begin(&highlighedPixmap); pixmapPainter.setCompositionMode(QPainter::CompositionMode_ColorDodge); pixmapP

我有一个QPixmap,它有一些透明区域。如何将高光/色调仅应用于具有非零alpha的区域

这就是我现在所拥有的,它为整个图像着色

QPixmap highlighedPixmap = myPixmap;
QPainter pixmapPainter;
pixmapPainter.begin(&highlighedPixmap);
pixmapPainter.setCompositionMode(QPainter::CompositionMode_ColorDodge);
pixmapPainter.fillRect(highlighedPixmap.rect(), QColor(180, 180, 180, 100));
pixmapPainter.end();
输入图像:

预期结果图像:


正确的选项是
合成模式\u sourcetop

QPixmap highlighedPixmap = myPixmap;
QPainter pixmapPainter(&highlighedPixmap);
pixmapPainter.setCompositionMode(QPainter::CompositionMode_SourceAtop);
pixmapPainter.fillRect(highlighedPixmap.rect(), foregroundColor);
pixmapPainter.end();

在…\examples\widgets\painting\composition的Qt目录中,有一个“compositionmodes”工具,可以让您尝试所有的合成模式。我在Qt5.2.1中找到了它,但至少从Qt4.8开始就应该在那里。

我可能有点遗漏了这一点,但是。。。我想你想在纯色背景上画高亮度的像素贴图。@G.M.嗯,我不明白你的意思。因此,
myPixmap
是我的原始图像,我想为该图像添加一个色调/高光,但使透明区域保持透明。我这样做会把透明的也染上颜色。谢谢你的回复。不幸的是,这在我的情况下不起作用。使用CompositionMode_SourceIn完全用foregroundColor覆盖我的原始图像。我想要一些混合的东西。有没有办法做到这一点?
CompositionMode\u SourceOver
可能是您的选择,但如果您可以提供输入和输出示例图像,那就更好了。
CompositionMode\u SourceOver
确实将图像与背景色混合,但也将原始图像的透明区域着色。有没有办法保持原始图像的透明部分不变?我在问题中添加了示例图像。好的,正确的选项应该是
CompositionMode\u sourcetop
。您可以在
…\examples\widgets\painting\composition
中的Qt目录中找到“composition Modes”工具,该工具允许您尝试所有合成模式。我在Qt5.2.1中找到了它,但至少从Qt4.8开始就应该有了。谢谢@mbjoe。结果很好。你能更新你的答案让我接受吗?