Converting to grayscale

S

Sirin Azazi

i am trying to convert an image into grayscale format. but i have a problem
saving the bmp file after the process.here the code;

for (int y = 0; y < Height; y++)

{

for (int x = 0; x < Width; x++)

{

Color c = img1.GetPixel(x, y);

int pxl= (int)(c.R * 0.3 + c.G * 0.59 + c.B * 0.11);

img1.SetPixel(x, y, Color.FromArgb(pxl, pxl, pxl));

img1.Save(filepath);

}

}





but i get an exception;

"External exception was unhandled.

A generic error occurred in GDI+. "



where s the problem?

thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top