Changing Colors
-
For example,you have picture(is painted with solid colors not gradiant) at mspaint, I would like to change all X color to Y color. How could i achive that? Is there any method at Drawing class (i coulnd find any :'()
hi, i think there is no direct method to accompolish this with C#.you have to use API like bitblt and compare the colors and change.. you can try with GDI/Graphic section...There is a lot of samples i found last time. good luck Where there is a will,there is a way.
-
For example,you have picture(is painted with solid colors not gradiant) at mspaint, I would like to change all X color to Y color. How could i achive that? Is there any method at Drawing class (i coulnd find any :'()
Hi, a simple way would be to load it as a Bitmap and to iterate over every pixel and use the GetPixel/setPixel functions on the bitmap to change pixel by pixel. As those calls are rather slow you could also go the unmanaged way. Have a look at Image Processing for Dummies by Christian Graus[^] for further details on this.
-
Hi, a simple way would be to load it as a Bitmap and to iterate over every pixel and use the GetPixel/setPixel functions on the bitmap to change pixel by pixel. As those calls are rather slow you could also go the unmanaged way. Have a look at Image Processing for Dummies by Christian Graus[^] for further details on this.
thank you I found this sample so GetPixel and SetPixel is ok for me. My new question is my picture box is set to Strech view. My image's width =768 , height=503 but on secreen, rightbottom corner pixel coordinat is x:460 y:261 So when i want to show color where mouse on over, it shows another color because of wrong coordinats. might i convert to coordinats?
Bitmap bitmap = new Bitmap("C:\\TV2.bmp"); int width = bitmap.Width; int height = bitmap.Height; int i, j; for (i = 0; i< width; i++) { for (j=0; j -- modified at 6:03 Friday 5th May, 2006
-
thank you I found this sample so GetPixel and SetPixel is ok for me. My new question is my picture box is set to Strech view. My image's width =768 , height=503 but on secreen, rightbottom corner pixel coordinat is x:460 y:261 So when i want to show color where mouse on over, it shows another color because of wrong coordinats. might i convert to coordinats?
Bitmap bitmap = new Bitmap("C:\\TV2.bmp"); int width = bitmap.Width; int height = bitmap.Height; int i, j; for (i = 0; i< width; i++) { for (j=0; j -- modified at 6:03 Friday 5th May, 2006
Hi, might be difficult because the PictureBox won't reveal this. You could try to calculate it yourself (not tested):
float sw = 1f * pictureBox.Width / bitmap.Width;
float sh = 1f * pictureBox.Height / bitmap.Height;
int xPic = xMouse * sw;
int yPic = yMouse * sh;where x/yMouse are the mouse coordinates you are getting and x/yPic should be the coordinates within the picture. But I don't know if this is accurate enough (might be that you'll also have to consider the border of the PictureBox).
-
For example,you have picture(is painted with solid colors not gradiant) at mspaint, I would like to change all X color to Y color. How could i achive that? Is there any method at Drawing class (i coulnd find any :'()
You can also replace colors using the ImageAttributes and ColorMap classes. Example replaces red->yellow, blue->magenta.
Graphics g = Graphics.FromImage(im); ImageAttributes attr = new ImageAttributes(); ColorMap[] remap = new ColorMap[2]; remap[0] = new ColorMap(); remap[0].OldColor = Color.Red; remap[0].NewColor = Color.Yellow; remap[1] = new ColorMap(); remap[1].OldColor = Color.Blue; remap[1].NewColor = Color.Magenta; attr.SetRemapTable(remap); g.DrawImage(im, new Rectangle(0, 0, im.Width, im.Height), 0, 0, im.Width, im.Height, GraphicsUnit.Pixel, attr);