gpt4 book ai didi

.net - 如何确定winform中给定颜色的禁用颜色?

转载 作者:行者123 更新时间:2023-12-02 03:23:21 27 4
gpt4 key购买 nike

Windows 窗体具有方便的 ControlPaint.DrawImageDisabled,可以在灰显、禁用状态下绘制彩色图像。对于给定的颜色,有没有办法确定禁用的颜色是什么(就好像它是由 DrawImageDisabled 绘制的一样)?

最佳答案

Reflector 告诉我们这是创建要使用的 ColorMatrix 的代码:

// In class-level declarations in ColorPaint
private static ImageAttributes disabledImageAttr;

// In the actual implementation method for DrawImageDisabled
if (disabledImageAttr == null)
{
float[][] newColorMatrix = new float[5][];
newColorMatrix[0] = new float[] { 0.2125f, 0.2125f, 0.2125f, 0f, 0f };
newColorMatrix[1] = new float[] { 0.2577f, 0.2577f, 0.2577f, 0f, 0f };
newColorMatrix[2] = new float[] { 0.0361f, 0.0361f, 0.0361f, 0f, 0f };
float[] numArray2 = new float[5];
numArray2[3] = 1f;
newColorMatrix[3] = numArray2;
newColorMatrix[4] = new float[] { 0.38f, 0.38f, 0.38f, 0f, 1f };
ColorMatrix matrix = new ColorMatrix(newColorMatrix);
disabledImageAttr = new ImageAttributes();
disabledImageAttr.ClearColorKey();
disabledImageAttr.SetColorMatrix(matrix);
}

// To draw the image itself
using (Bitmap bitmap = new Bitmap(image.Width, image.Height))
{
using (Graphics graphics2 = Graphics.FromImage(bitmap))
{
graphics2.DrawImage(image, new Rectangle(0, 0, size.Width, size.Height), 0, 0, size.Width, size.Height, GraphicsUnit.Pixel, disabledImageAttr);
}
graphics.DrawImageUnscaled(bitmap, imageBounds);
return;
}

关于.net - 如何确定winform中给定颜色的禁用颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1069491/

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