如何绘制色彩范围更柔和的图像?

发布于 2024-12-29 13:25:42 字数 372 浏览 0 评论 0原文

我已经为 .NET 实现了自定义 TreeListView,并且我想添加 Ctrl+X / Ctrl+V 功能。

我希望当用户剪切节点时,节点图像渲染得比平常更柔和,就像 Windows 资源管理器那样:

enter image description这里

有人可以解释如何在 C# 中使用 System.Drawing.Image 来做到这一点吗?我使用 Graphics.DrawImage 来绘制图像,所以我需要一个函数来转换图标。

有没有内置的算法可以做到这一点?有什么例子吗?

I have implemented a custom TreeListView for .NET and I want to add Ctrl+X / Ctrl+V functionality.

I want that when the user cuts a node, the node image is rendered softer than usually, as the windows explorer does:

enter image description here

Someone could explain how to do it with a System.Drawing.Image in C#? I use Graphics.DrawImage to draw images, so I need a function to transform the icon.

Is there any built-in algorithm to do it? Any example?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

友欢 2025-01-05 13:25:42

您可以在顶部绘制一个部分透明的白色矩形。比重新计算所有像素更容易。

You could draw a white rectangle on top that is partially transparent. Easier than re-calculating all the pixels.

じее 2025-01-05 13:25:42

我不会改变图像的颜色,而是让图像更加透明。您可以使用ColorMatrix,如其他答案使用一个矩阵,使 alpha 通道达到 50% 左右。

float[][] colorMatrixElements = { 
   new float[] {1, 0, 0, 0, 0},
   new float[] {0, 1, 0, 0, 0},
   new float[] {0, 0, 1, 0, 0},
   new float[] {0, 0, 0, 0.5f, 0},        // alpha scaling factor of 50%
   new float[] {0, 0, 0, 0, 1}};

ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);

Instead of changing the color of the image, I would just make the image more transparent. You could use the ColorMatrix as mentioned in the other answers with a matrix that makes the alpha channel 50% or so.

float[][] colorMatrixElements = { 
   new float[] {1, 0, 0, 0, 0},
   new float[] {0, 1, 0, 0, 0},
   new float[] {0, 0, 1, 0, 0},
   new float[] {0, 0, 0, 0.5f, 0},        // alpha scaling factor of 50%
   new float[] {0, 0, 0, 0, 1}};

ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
千纸鹤带着心事 2025-01-05 13:25:42

有关示例,请参阅 ColorMatrix 类以及 <从那里链接的 href="http://msdn.microsoft.com/en-us/library/a7xw19wh.aspx" rel="nofollow">重新着色图像 页面。您应该能够在此处和所有互联网上搜索 ColorMatrix 找到更多信息。

请注意,ColorMatrix 类在 RGBA 空间中工作,因此对颜色执行转换以调整亮度和饱和度并不是那么简单。在 HSV 领域做这类事情通常更容易。在 RGBA 空间中,您可能最好简单地调整 Alpha 通道 (A),以使颜色显得更淡。

如果您只有一小部分有限的图标,那么使用您最喜欢的 Photoshop 克隆手动制作第二组颜色调整后的图标通常会更容易。

See the ColorMatrix class for examples also the Recoloring Images page linked from there. You should be able to find more info searching for ColorMatrix on both here and all of the internets.

Note that the ColorMatrix class works in the RGBA space so performing transformations on the colours to adjust brightness and saturation is not that straightforward. It's often easier to do this kind of stuff in the HSV space. In the RGBA space you might be best off simply adjusting the alpha channel (A) so that the colours appear fainter.

If you have only a small, finite set of icons then it's often easier just to manually make a second set of colour adjusted icons using your favourite Photoshop clone.

十雾 2025-01-05 13:25:42

更改图像的亮度。

我在此处找到了一些链接这里


但如果我是你,我会简化它,只使用我在外部修改的不同图像,而不是以编程方式进行。

Change brightness of the image.

I found some links here and here.


But if I were you, I would simplify it and just use a different image that I had modified externally instead of doing it programmatically.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文