ListView 图像选择蒙版

发布于 2024-12-07 16:53:46 字数 1328 浏览 0 评论 0原文

我在 View = LargeIcons 中有一个 ListView。我添加了一个 PNG 图标(黑色,白色背景,32 位 ARGB)和两个使用 System.Drawing.Graphics 制作的图标(白色背景,Pixelformat 32bppArgb)。

当我选择列表中的图标时,PNG 被很好地屏蔽/突出显示,但是我以编程方式绘制的自定义图标在屏蔽/突出显示时具有可怕的伪影(屏幕截图中的最后两个)。

看看: 在此处输入图像描述

如何使我的图标与外部图形一样精细?


生成代码:

    Bitmap bmp = new Bitmap(THUMB_WIDTH, THUMB_HEIGHT, formatThumbs);
    using(Graphics g = Graphics.FromImage(bmp))
    {
        g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
        g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
        g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
        g.Clear(Color.White);                
        g.DrawEllipse(penThumbLine, 1, 1, THUMB_WIDTH - 2, THUMB_HEIGHT - 2);
    }
    return bmp;

当我将 Clear 颜色更改为 Color.Transparent 时,选择条目/图标时不会突出显示。 ImageList TransparentColorColor.Transparent

I have a ListView in View = LargeIcons. I added an icon which I have done as PNG (black with white background, 32bit ARGB) and two icons I have done with System.Drawing.Graphics (white background, Pixelformat 32bppArgb).

When I selected the icons in the list, the PNG is masked/highlighted fine, but my custom icons drawn programatically have awful artefacts when masked/highlighted (last two ones in the screenshot).

Have a look:
enter image description here

How can I render my icons as fine as the external graphic?


Generation code:

    Bitmap bmp = new Bitmap(THUMB_WIDTH, THUMB_HEIGHT, formatThumbs);
    using(Graphics g = Graphics.FromImage(bmp))
    {
        g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
        g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
        g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
        g.Clear(Color.White);                
        g.DrawEllipse(penThumbLine, 1, 1, THUMB_WIDTH - 2, THUMB_HEIGHT - 2);
    }
    return bmp;

When I change the Clear color to Color.Transparent there is no highlight visible when the entry/icon is selected. The ImageList TransparentColor is Color.Transparent.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文