c# - GetPixel method is not found -


i have simple program, , ive included system.drawing , not have ability use getpixel() method. says not found. reason this?

using system.drawing;  namespace isolatepixels {     class program     {         static void main(string[] args)         {              system.drawing.image image1 = system.drawing.image.fromfile(@"c:\1.jpg");              int x, y;              // loop through images pixels reset color.              (x = 0; x < image1.width; x++)             {                 (y = 0; y < image1.height; y++)                 {                     color pixelcolor = image1.getpixel(x, y);                     color newcolor = color.fromargb(pixelcolor.r, 0, 0);                     image1.setpixel(x, y, newcolor);                 }             }            }     } } 

[edit] hans says in comment above, can skip image.fromfile() , pass filename directly bitmap constructor if not using image anywhere.

an image object doesn't contain methods , nor graphics object, bitmap object does. trick create bitmap image, using new bitmap(image) so:

// don't need this: image image1 = image.fromfile(@"c:\1.jpg"); bitmap bitmap = new bitmap(@"c:\1.jpg");  // save image in jpeg format. bitmap.save(@"c:\test.bmp", system.drawing.imaging.imageformat.bmp);  int x, y;  // loop through images pixels reset color.   (x = 0; x < bitmap.width; x++) {     (y = 0; y < bitmap.height; y++)     {         color pixelcolor = bitmap.getpixel(x, y);         color newcolor = color.fromargb(pixelcolor.r, 0, 0);         bitmap.setpixel(x, y, newcolor);     } } 

note bitmap derives system.drawing.image.

i think should work.


Comments