gpt4 book ai didi

Aero:如何在玻璃上绘制纯色(不透明)颜色?

转载 作者:行者123 更新时间:2023-12-03 08:59:01 30 4
gpt4 key购买 nike

使用 GDI+ 绘制各种颜色:

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

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

如何在玻璃上绘制纯色?

您还会注意到,完全不透明的颜色会根据它的颜色进行不同的处理:
  • 不透明黑色:完全透明
  • 不透明颜色:部分透明
  • 不透明白色:完全不透明

  • alt text

    谁能指出我在桌面合成器上解释如何处理不同颜色的文档?

    更新 3

    您还会注意到 FillRectangle行为不同于 FillEllipse :
  • FillEllipse with an opaque color 绘制不透明颜色
  • FillRectangle使用不透明颜色绘制部分(或完全)透明

  • alt text

    请解释无意义的行为。

    更新 4

    Alwayslearning建议我更改合成模式。来自 MSDN :

    CompositingMode Enumeration

    The CompositingMode enumeration specifies how rendered colors are combined with background colors. This enumeration is used by the Graphics::GetCompositingMode and 'Graphics::SetCompositingMode' methods of the Graphics class.

    CompositingModeSourceOver

    Specifies that when a color is rendered, it is blended with the background color. The blend is determined by the alpha component of the color being rendered.

    CompositingModeSourceCopy

    Specifies that when a color is rendered, it overwrites the background color. This mode cannot be used along with TextRenderingHintClearTypeGridFit.



    来自 CompositingModeSourceCopy 的描述,听起来这不是我想要的选项。从它施加的限制来看,这听起来像是我想要的选择。使用合成或透明度禁用它 不是 我想要的选项,因为它执行 SourceCopy ,而不是 SourceBlend :

    alt text

    幸运的是,这不是我必须考虑的邪恶,因为它不能解决我的实际问题。构建我的 graphics 之后对象,我尝试更改合成模式:
    graphics = new Graphics(hDC);
    graphics.SetCompositingMode(CompositingModeSourceCopy); //CompositingModeSourceCopy = 1

    结果对输出没有影响:

    alt text

    笔记
  • Win32原生
  • 不是 .NET(即 native )
  • 不是 Winforms(即 native )
  • GDI+(即原生)

  • 也可以看看
  • Aero: How to draw ClearType text on glass?
  • Windows Aero: What color to paint to make “glass” appear?
  • Vista/7: How to get glass color?
  • 最佳答案

    对我来说似乎工作正常。由于缺乏完整的代码示例,我假设您的合成模式错误。

    public void RenderGdiPlus()
    {
    List<string> colors = new List<string>(new string[] { "000000", "ff0000", "00ff00", "0000ff", "ffffff" });
    List<string> alphas = new List<string>(new string[] { "00", "01", "40", "80", "c0", "fe", "ff" });
    Bitmap bmp = new Bitmap(200, 300, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

    Graphics graphics = Graphics.FromImage(bmp);
    graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
    graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.None;
    graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;

    graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
    graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
    SolidBrush backBrush = new SolidBrush(Color.FromArgb(254, 131, 208, 129));
    graphics.FillRectangle(backBrush, 0, 0, 300, 300);

    graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
    Pen pen = new Pen(Color.Gray);
    for (int row = 0; row < alphas.Count; row++)
    {
    string alpha = alphas[row];
    for (int column=0; column<colors.Count; column++)
    {
    string color = "#" + alpha + colors[column];
    SolidBrush brush = new SolidBrush(ColorTranslator.FromHtml(color));
    graphics.DrawRectangle(pen, 40*column, 40*row, 32, 32);
    graphics.FillRectangle(brush, 1+40*column, 1+40*row, 31, 31);
    }
    }

    Graphics gr2 = Graphics.FromHwnd(this.Handle);
    gr2.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
    gr2.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
    gr2.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.None;
    gr2.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
    gr2.DrawImage(bmp, 0, 0);
    }

    关于Aero:如何在玻璃上绘制纯色(不透明)颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4258295/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com