This is a bad approach, but many reasons. First of all, the two: 1) it's too difficult, unreliable and hard to maintain, 2) absolutely non needed.
Assuming you want to use
System.Drawing
, you need to do the following:
- Use the class
System.Drawing.Bitmap
; read the bitmap from file using one of its constructors. - Create a target bitmap with the different pixel format (whatever you need, like 8 bits per pixel) and the same size.
- Get access to source bitmap and target bitmaps using
System.Drawing.Bitmap.LockBits
; move data appropriately with the conversion of each bit you need. - PROFIT!
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx[
^],
http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx[
^] (find a code sample here).
Important! Don't even think about using
GetPixel/SetPixel
— it would be too slow.
WPF have its own approach. Look at
System.Windows.Media.Imaging.WriteableBitmat
, see
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx[
^].
—SA