如何在GDI +中合并两种颜色?

编程入门 行业动态 更新时间:2024-10-10 13:13:10
本文介绍了如何在GDI +中合并两种颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想将两种颜色合并为新颜色.

Iwant to merge two colors into new color.

这是我现在的操作方式:

Here is how I do it now:

位图 bmp = 位图 (50,50);

Bitmap bmp = new Bitmap(50, 50);

图形 g = 图形 .FromImage(bmp);

Graphics g = Graphics.FromImage(bmp);

矩形 r = 矩形 (0,0,50,50);

Rectangle r = new Rectangle(0, 0, 50, 50);

颜色 rc = 颜色 .FromArgb(100,250,0,0);

Color rc = Color.FromArgb(100, 250, 0, 0);

SolidBrush b = SolidBrush (rc);

SolidBrush b = new SolidBrush(rc);

颜色 rc1 = 颜色 .FromArgb(100,0,0,250);

Color rc1 = Color.FromArgb(100, 0, 0, 250);

SolidBrush b1 = SolidBrush (rc1);

SolidBrush b1 = new SolidBrush(rc1);

g.CompositingQuality = CompositingQuality .GammaCorrected;

g.CompositingQuality = CompositingQuality.GammaCorrected;

g.FillRectangle(b,r);

g.FillRectangle(b, r);

g.FillRectangle(b1,r);

g.FillRectangle(b1, r);

颜色 c = bmp.GetPixel(10,10);

//此代码我想使用不带返回颜色的g

// this code i want to use g of return color without

颜色 c = bmp.GetPixel(10,10);

,但不使用功能 bmp.getpixel

but without use function bmp.getpixel

我想在合并后使用图形两种颜色

i want to use Graphics in merged two color

举个例子

谢谢

推荐答案

嗨!

我认为您需要阅读有关"颜色空间",这样您就可以工作了颜色.

I think you need read about "Color spaces" so you will be able to work with colors.

通常,您需要将红色,绿色和红色混合在一起.颜色中的蓝色分量按指定比例并归一化为0-255范围.

Generally you need to mix Red, Green & Blue components of the color into specified proportions and normalize to 0-255 range.

这里是我的程序之一的示例-它混合了颜色(我在那里没有进行归一化,但是可以用):

Here is sample from one of my programs - it mix colors (I don't make normalization there, but it worked):

public 静态 颜色混合(颜色从,颜色到, float 百分比)

public static Color Mix(Color from, Color to, float percent)

{

float amountFrom = 1.0f-百分比;

float amountFrom = 1.0f - percent;

返回 Color.FromArgb(

return Color.FromArgb(

( int )(从.A *数量从+到.A *百分比),

(int)(from.A * amountFrom + to.A * percent),

( int )(from.R * amountFrom + to.R *百分比),

(int)(from.R * amountFrom + to.R * percent),

( int )(from.G * amountFrom + to.G *百分比),

(int)(from.G * amountFrom + to.G * percent),

( int )(from.B * amountFrom + to.B *百分比));

(int)(from.B * amountFrom + to.B * percent));

}

更多推荐

如何在GDI +中合并两种颜色?

本文发布于:2023-11-28 21:55:44,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两种   颜色   如何在   GDI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!