如何绘制色彩范围更柔和的图像?
我已经为 .NET 实现了自定义 TreeListView
,并且我想添加 Ctrl+X / Ctrl+V
功能。
我希望当用户剪切节点时,节点图像渲染得比平常更柔和,就像 Windows 资源管理器那样:
有人可以解释如何在 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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在顶部绘制一个部分透明的白色矩形。比重新计算所有像素更容易。
You could draw a white rectangle on top that is partially transparent. Easier than re-calculating all the pixels.
我不会改变图像的颜色,而是让图像更加透明。您可以使用ColorMatrix,如其他答案使用一个矩阵,使 alpha 通道达到 50% 左右。
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.
有关示例,请参阅 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.
更改图像的亮度。
我在此处找到了一些链接这里。
但如果我是你,我会简化它,只使用我在外部修改的不同图像,而不是以编程方式进行。
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.