改变图片颜色 [英] Change picture color

查看:92
本文介绍了改变图片颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个图片框和一个3按钮(红色,绿色,蓝色)





我的目标是创建程序在vb.net中,只需单击上面的一个按钮就可以改变图像的颜色。





无论我的图像是什么只要颜色会改变,就会穿上它。







请帮我提供一个代码或仅仅出于教育目的对此进行编程。



紧急删除 - OriginalGriff [/ edit]





对不起我做了什么,我的目标是,如果我按绿色按钮,图像颜色将变为绿色。在图像上放置绿色。





现在不紧急。

let say i have a picturebox and a 3 button(red,green,blue)


My aim is to create program in vb.net that will change the color of an image by just clicking 1 of the buttons above.


no matter what image i will put on this as long as the color will change.



please help me give a code or program about this just for educational purposes.

[edit]Urgency deleted - OriginalGriff[/edit]


sorry what i have done, my goal is that if i press the button green the image color will change to color green. put green color on the image.


its not urgent now.

推荐答案

public static Bitmap SetColorFilter(Color color,Bitmap _currentBitmap)

{

Bitmap temp =(Bitmap)_currentBitmap;

Bitmap bmap = (位图)temp.Clone();

颜色c;

for(int i = 0; i< bmap.Width; i ++)

{

for(int j = 0; j< bmap.Height; j ++)

{

c = bmap.GetPixel(i ,j);

int nPixelR = 0;

int nPixelG = 0;

int nPixelB = 0;

if(color == Color.Red)

{

nPixelR = cR;

nPixelG = cG - 255;

nPixelB = cB - 255;

}

否则如果(color == Color.Green)

{

nPixelR = cR - 255;

nPixelG = cG;

nPixelB = cB - 255;

}

否则if(color == Color.Blue)

{

nPixelR = cR - 255;

nPixelG = cG - 255;

nPixelB = cB;

}

nPixelR = Math.Max(nPixelR,0);

nPixelR = Math.Min(255,nPixelR);



nPixelG = Math.Max(nPixelG,0);

nPixelG = Math.Min(255,nPixelG);



nPixelB = Math.Max( nPixelB,0);

nPixelB = Math.Min(255,nPixelB);



bmap.SetPixel(i,j,Color。 FromArgb((byte)nPixelR,

(字节)nPixelG,(字节)nPixelB));

}

}

_currentBitmap =(Bitmap)bmap.Clone();

返回_currentBitmap;

}



//并点击按钮



public static Bitmap SetColorFilter(Color color, Bitmap _currentBitmap)
{
Bitmap temp = (Bitmap)_currentBitmap;
Bitmap bmap = (Bitmap)temp.Clone();
Color c;
for (int i = 0; i < bmap.Width; i++)
{
for (int j = 0; j < bmap.Height; j++)
{
c = bmap.GetPixel(i, j);
int nPixelR = 0;
int nPixelG = 0;
int nPixelB = 0;
if (color == Color.Red)
{
nPixelR = c.R;
nPixelG = c.G - 255;
nPixelB = c.B - 255;
}
else if (color == Color.Green)
{
nPixelR = c.R - 255;
nPixelG = c.G;
nPixelB = c.B - 255;
}
else if (color == Color.Blue)
{
nPixelR = c.R - 255;
nPixelG = c.G - 255;
nPixelB = c.B;
}
nPixelR = Math.Max(nPixelR, 0);
nPixelR = Math.Min(255, nPixelR);

nPixelG = Math.Max(nPixelG, 0);
nPixelG = Math.Min(255, nPixelG);

nPixelB = Math.Max(nPixelB, 0);
nPixelB = Math.Min(255, nPixelB);

bmap.SetPixel(i, j, Color.FromArgb((byte)nPixelR,
(byte)nPixelG, (byte)nPixelB));
}
}
_currentBitmap = (Bitmap)bmap.Clone();
return _currentBitmap;
}

//and on button click

protected void ButtonRed_Click(object sender, EventArgs e)
   {
       Bitmap b = (Bitmap)Bitmap.FromFile(Server.MapPath("~") + "/p1.jpg");
       Bitmap image = SetColorFilter(Color.Red,b);
       image.Save(Server.MapPath("~") + "/Thumbnail.bmp");
       Image1.ImageUrl = "~/Thumbnail.bmp";
   }


这篇关于改变图片颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆