Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 3-Oct-13 23:16pm
v3
Comments
OriginalGriff 4-Oct-13 4:26am    
Urgency deleted: It may be urgent to you, but it isn't to us. All that your stressing the urgency does is to make us think you have left it too late, and want us to do it for you. This annoys some people, and can slow a response.
OriginalGriff 4-Oct-13 4:27am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
So bear in mind that we have no idea what you want the buttons to actually do: are you suggesting that if you click on a button it should remove that colour from the image? or what?
Use the "Improve question" widget to edit your question and provide better information.
[no name] 4-Oct-13 6:19am    
Crixalis : Without trying anything how could suggest to someone to do the same for you.. first of all try and then ask so some one can help you..!!1 otherwise no body could assume your output or goal.!!!

1 solution

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

C#
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";
   }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900