本文介绍了如何在GDI +中合并两种颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want 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 +中合并两种颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 23:47