本文介绍了航空:如何在玻璃上绘制纯色(不透明)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用GDI +绘制各种颜色:

  brush = new SolidBrush(color); 
graphics.FillRectangle(brush,x,y,width,height);

您会注意到玻璃上没有正确显示不透明的颜色:



我如何在玻璃上绘制纯色?




您还会注意到,完全不透明的颜色根据其颜色的不同而有所不同:




  • 不透明黑色:完全透明

  • 不透明颜色:部分透明

  • 不透明白色:完全不透明





有人可以指出我在桌面合成器上的文档,该文档解释了如何处理不同的颜色吗?






更新3



您还会注意到 FillRectangle 的行为不同于 FillEllipse




  • FillEllipse 绘制不透明颜色

  • FillRectangle 具有不透明的颜色部分(或完全)绘制透明





对非理性行为的解释



更新4







  • 解决方案

    再过一天




    • 将要显示在玻璃上的所有内容绘制到位图中。

    • 然后,用黑色清除表单背景。

    • 此后,立即在表单上绘制位图。


    $ b但是,$ b

    (与其他任何不使用DrawThemeTextEx的解决方案一样):
    文本渲染将无法正常工作,因为它始终将表单的底色用作抗锯齿/清除类型提示。请改用DrawThemeTextEx,它还支持后面带有发光效果的文本。


    Using GDI+ to draw various colors:

    brush = new SolidBrush(color);
    graphics.FillRectangle(brush, x, y, width, height);
    

    You'll notice that no opaque color shows properly on glass:

    How do i draw solid colors on glass?


    You'll also notice that a fully opaque color is handled differently depending on what color it is:

    • opaque black: fully transparent
    • opaque color: partially transparent
    • opaque white: fully opaque

    Can anyone point me to the documentation on the desktop compositor that explains how different colors are handled?


    Update 3

    You'll also notice that FillRectangle behaves differently than FillEllipse:

    • FillEllipse with an opaque color draws an opaque color
    • FillRectangle with an opaque color draws partially (or fully) transparent

    Explanation for non-sensical behavior please.

    Update 4

    Alwayslearning suggested i change the compositing mode. From MSDN:

    From the description of CompositingModeSourceCopy, it sounds like it's not the option i want. From the limitations it imposes, it sounds like the option i want. And with composition, or transparency disabled it isn't the option i want, since it performs a SourceCopy, rather than SourceBlend:

    Fortunately it's not an evil i have to contemplate because it doesn't solve my actual issue. After constructing my graphics object, i tried changed the compositing mode:

    graphics = new Graphics(hDC);
    graphics.SetCompositingMode(CompositingModeSourceCopy); //CompositingModeSourceCopy = 1
    

    The result has no effect on the output:

    Notes

    • Win32 native
    • not .NET (i.e. native)
    • not Winforms (i.e. native)
    • GDI+ (i.e. native)

    See also

    解决方案

    Another day, another solution by me.

    • Draw everything you want to appear on glass into a bitmap.
    • Then, clear the form background with black color.
    • Immediately after this, draw the bitmap on your form.

    However (as with any other solution not using DrawThemeTextEx):Text rendering will not work correctly, because it always takes the back color of your form as an antialias/cleartype hint. Use DrawThemeTextEx instead, which also supports text with a glow effect behind.

    这篇关于航空:如何在玻璃上绘制纯色(不透明)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-23 09:19