-
GDI+ / Dithering
My question is a GDI+ question with VB .NET. I need to create graphics from text and save the images as indexed bitmap files either 1 or 4 bit. Here's what I'm doing so far:
Dim newBitmap as Bitmap
Dim g as Graphics
Dim myFont as New Font("Comic Sans MS", 24)
newBitmap = New Bitmap(720, 50, Drawing.Imaging.PixelFormat.Format24bppRgb)
g = Graphics.FromImage(newBitmap)
g.FillRectangle(New SolidBrush(Color.Black), New Rectangle(0, 0, 720, 50))
g.DrawString("Hello World", myFont, New SolidBrush(Color.White), 0, 0)
newBitmap.Save("c:\test.bmp", Drawing.Imaging.ImageFormat.Bmp)
g.Dispose()
newBitmap.Dispose()
This works and creates the file c:\test.bmp with white text on a black background. All good so far but... the application this is for will ONLY accept bitmaps with 16 or less colors (1 or 4 bit indexed). The Drawing.Imaging.PixelFormat provides both Format1bppIndexed and Format4bppIndexed BUT you can not create a graphics object from an indexed pixel format bitmap and without the graphics object I can not use the Drawstring method.
I've tried to use the bitmap.clone method, which takes a pixel format parameter, but it hangs if the pixel fomat is less than that of the source bitmap.
My question: how can I convert (reduce the color depth) of a bitmap in VB .NET? My source image only has 2 colors (solid black and solid white) so I should not have any dithering problems but I simply don't know how to do the reduction and I've been unable to find a resource to help.
Thanks for any information you can give me.