C# 图片叠加 不明白你怎么合... Red + green = yellow?这样 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 比如说 图A中有一红色的矩形,叠加到图B上时为一为红色且通明的矩形(能够看到原图A的东西,但就是蒙上了一层通明的红色) 我写了个demo,可以实现了。private void button1_Click(object sender, EventArgs e) { Color c = new Color(); Bitmap box1 = new Bitmap(pictureBox1.Image); Bitmap box2 = new Bitmap(pictureBox2.Image); Bitmap box3 = new Bitmap(pictureBox2.Image); for (int i = 0; i < pictureBox1.Image.Width; i++) { for (int j = 0; j < pictureBox1.Image.Height; j++) { c = box2.GetPixel(i, j); //去Picture2的颜色。 if (c == Color.FromArgb(255,255,255)) { c = box1.GetPixel(i, j); //如果是白色就取Picture1的颜色 } if (c == Color.FromArgb(255, 0, 0)) { c = Color.FromArgb(20, c); //如果是红色就做半透明处理Alpha = 20; } box3.SetPixel(i, j, c); } pictureBox1.Refresh(); pictureBox1.Image = box3; } }注意两个PictureBox的属性设置,否则会造成益处: this.pictureBox1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox1.BackgroundImage"))); this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image"))); this.pictureBox1.Location = new System.Drawing.Point(41, 60); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(243, 224); this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; // // pictureBox2 // this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image"))); this.pictureBox2.Location = new System.Drawing.Point(338, 60); this.pictureBox2.Name = "pictureBox2"; this.pictureBox2.Size = new System.Drawing.Size(243, 224); this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBox2.TabIndex = 1; this.pictureBox2.TabStop = false; 使用 System.Drawing.Drawing2D.Matrix 改变Alpha值。Matrix是一个矩阵,从0-1成倍的变换。 把IMAGE2转换成灰度图 fb(,),其中的黑白色不变,红色成了灰色。将fB(,) 的值调整为 0~1 之前的浮点数。将fB(,)做为 Image2 叠加的透明通道,即 fLast (,) = Image1(,) + Image2(,) * fB(,); 明白了点你先知道 你红色的区域..并获取到Rectangle使用Grapchis.FillRectangle(new SolidBrush(Color.FromArgb(0,255,255,255)) 绘制成全透明的图Grapchis.FillRectangle(new SolidBrush(Color.FromArgb(100, 255, 255, 255))然后绘制成半透明的图.然后把这个图形绘制到你要绘制的地方就可以了.. 你试下没试过:) 错误 1 当前上下文中不存在名称“resources” C:\Documents and Settings\Administrator\桌面\565465\WindowsApplication1\WindowsApplication1\Form1.cs 49 72 WindowsApplication1请问下面的resources是什么对象啊????this.pictureBox1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox1.BackgroundImage"))); c# 有关vs2003的一些疑问 做一个多语言网站 首先预祝大家新年愉快!提前拜年了!我想请教进程相关的一些问题: C#导出excel,固定模板问题 怎样把一个string传给一个DateTimePicker控件 关于自动动态生成combox取值的问题 字符串编码的问题 如何判断一个字符串是不地数值? 那里有有关分布式计算和多层应用的C#的资料? 新手求助,C#代码的理解 Silverlight多语言支持问题
{
Color c = new Color();
Bitmap box1 = new Bitmap(pictureBox1.Image);
Bitmap box2 = new Bitmap(pictureBox2.Image);
Bitmap box3 = new Bitmap(pictureBox2.Image);
for (int i = 0; i < pictureBox1.Image.Width; i++)
{
for (int j = 0; j < pictureBox1.Image.Height; j++)
{
c = box2.GetPixel(i, j); //去Picture2的颜色。 if (c == Color.FromArgb(255,255,255))
{
c = box1.GetPixel(i, j); //如果是白色就取Picture1的颜色 }
if (c == Color.FromArgb(255, 0, 0))
{
c = Color.FromArgb(20, c); //如果是红色就做半透明处理Alpha = 20;
} box3.SetPixel(i, j, c);
}
pictureBox1.Refresh();
pictureBox1.Image = box3;
} }
注意两个PictureBox的属性设置,否则会造成益处: this.pictureBox1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox1.BackgroundImage")));
this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(41, 60);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(243, 224);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// pictureBox2
//
this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));
this.pictureBox2.Location = new System.Drawing.Point(338, 60);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(243, 224);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox2.TabIndex = 1;
this.pictureBox2.TabStop = false;
Matrix是一个矩阵,从0-1成倍的变换。
将fB(,) 的值调整为 0~1 之前的浮点数。
将fB(,)做为 Image2 叠加的透明通道,即 fLast (,) = Image1(,) + Image2(,) * fB(,);
你先知道 你红色的区域..并获取到Rectangle
使用
Grapchis.FillRectangle(new SolidBrush(Color.FromArgb(0,255,255,255))
绘制成全透明的图
Grapchis.FillRectangle(new SolidBrush(Color.FromArgb(100, 255, 255, 255))
然后绘制成半透明的图.然后把这个图形绘制到你要绘制的地方就可以了.. 你试下没试过:)
请问下面的resources是什么对象啊????
this.pictureBox1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox1.BackgroundImage")));