First rule. Do not use
GetPixel/SetPixel
: it's too slow! You can get acceptable performance only when you do it all at once.
Do the following. Create empty bitmap of the class
System.Drawing.Bitmap
and use
System.Drawing.Bitmap.LockBits
method. For pixelFormat, use
System.Drawing.Imaging.PixelFormat.Format32bppPArgb
(precisely this one, this is what you minimally need). Fill in the value of each pixel from your 2-2-2-2 data. Convert your 2-bit components for each color and opacity to 8-bit, so you maximum value of 3 is mapped to 255:
byte component8 = component2 * 85
(sic!).
The code sample on this page will give you the idea how to address pixels and move data:
http://msdn.microsoft.com/en-us/library/5ey6h79d(v=VS.100).aspx[
^]. Pay attention for the use of
System.Runtime.InteropServices.Marshal
.
That should be enough to solve your problem.
—SA