-2

I'm new on programming. I'm a student in a univesity. Is it possible to use visual studio for converting RGB images to grayscale with C#?

There is a specific folder that includes RGB jpeg images and every day it has new jpg files too. I need to make an exe file for converting them to grayscale.

Do I have to install new libraries for this work or are standard libraries of VS2013 enough for this?

Abbas
  • 13,285
  • 6
  • 39
  • 67
user3218867
  • 13
  • 1
  • 5

1 Answers1

1

The standard libraries are enough.

I once used this code:

public static Bitmap GrauwertBild(Bitmap input) 
{
  Bitmap greyscale = new Bitmap(input.Width, input.Height);
  for (int x = 0; x < input.Width; x++)
  {
    for (int y = 0; y < input.Height; y++)
    {
     Color pixelColor = input.GetPixel(x, y);
     //  0.3 · r + 0.59 · g + 0.11 · b
     int grey = (int)(pixelColor.R * 0.3 + pixelColor.G * 0.59 + pixelColor.B * 0.11);
     greyscale.SetPixel(x, y, Color.FromArgb(pixelColor.A, grey , grey , grey ));
    }
  }
  return greyscale;
}
citronas
  • 17,809
  • 26
  • 85
  • 155
  • is this code convert all jpg images with same name to grayscale? and how can i import my folder on this code? – user3218867 Feb 03 '14 at 12:55
  • It converts a single image, that has been read by standard framework methods into a bitmap. Use Bitmap.Save (or how exactly that method is called) to save the image back to a specified path. – citronas Feb 03 '14 at 18:23