I need to process and save the images in the original bpp (1 for BnW, 8 for gray, 24 for color). After processing, I always have 24bpp (due to processing with Aforge.Net). I pass the original bpp function to save, and I use the following code to save:
private static Bitmap changePixelFormat(Bitmap input, PixelFormat format)
{
Bitmap retval = new Bitmap(input.Width, input.Height, format);
retval.SetResolution(input.HorizontalResolution, input.VerticalResolution);
Graphics g = Graphics.FromImage(retval);
g.DrawImage(input, 0, 0);
g.Dispose();
return retval;
}
When I pass:
PixelFormat.Format8bppIndexed
I get an exception: "A graphic cannot create an image in indexed pixel format" on the line:
Graphics g = Graphics.FromImage(retval);
I tried the following code:
Bitmap s = new Bitmap("gray.jpg");
Bitmap NewPicture = s.Clone(new Rectangle(0, 0, s.Width, s.Height), PixelFormat.Format8bppIndexed);
After that, "NewImage" has a PixelFormat 8bppIndexed, but when I save NewImage:
NewPicture.Save("hello.jpg", ImageFormat.Jpeg);
hello.jpg has 24bpp.
I need to save bpp format and image source image.
Why does Bitmap.Save ignore PixelFormat Bitmap?
==================================================== =====
, , :
http://freeimage.sourceforge.net/license.html
( JPEG) 8- .