2: GDI+ doesn't support this. There is however a trick available that you can play with the GIF image encoder. The result isn't always very good, the encoder uses dithering if necessary. You can only generate the 8bpp indexed format. Here's the code:
public static Image Image2Indexed8bpp(Image img) { System.IO.MemoryStream buffer = new System.IO.MemoryStream(); img.Save(buffer, System.Drawing.Imaging.ImageFormat.Gif); buffer.Seek(0, System.IO.SeekOrigin.Begin); return Bitmap.FromStream(buffer); }
3: The Graphics class can do this for you. Here's the code:
public static Image Indexed2Image(Image img, System.Drawing.Imaging.PixelFormat fmt) { Image bmp = new Bitmap(img.Width, img.Height, fmt); Graphics gr = Graphics.FromImage(bmp); gr.DrawImage(img, 0, 0); gr.Dispose(); return bmp; }