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";
}