Here is the idea:
1) Use the class
System.Drawing.Bitmap
, create an instance using the constructor
Bitmap(Int32, Int32, PixelFormat)
. For
PixelFormat
, use
System.Drawing.Imaging.PixelFormat.Format1bppIndexed
to have the minimal 1-bit black-and-white format. Make the bitmap size 20x20.
2) Get an instance of
System.Drawing.Graphics
using its static factory method
System.Drawing.Graphics.FromImage
using an instance of your bitmap as a parameter.
3) Using the instance of
System.Drawing.Graphics
, draw the text on your bitmap using one of the
System.Drawing.Graphics.DrawString
methods.
This is a delicate step: you need to select appropriate font (probably monospace), its size and location to fit a character in your 20x20 matrix and position (say, center) it properly. Some minor experimenting can help.
It will be a challenge to find a font good for such a small matrix, but I believe it's possible. With old text-mode PC programs I used to use even smaller matrices.
4) Don't forget to dispose the instance of
System.Drawing.Graphics
. It's the best to declare and use the instance under the "using" statement. Same thing stands about the instance of
System.Drawing.Bitmap
; see
http://msdn.microsoft.com/en-us/library/yh598w02%28v=VS.100%29.aspx[
^].
5) To get access to the bitmap's bits, use the method
System.Drawing.Bitmap.LockBits
and
System.Runtime.InteropServices.Marshal
; see the code sample here:
http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx[
^], but don't forget you have only one bit per pixel.
6) Use the array of bitmap bits and
bmpData.Stride
(see the code sample referenced above) to address your bits on your physical matrix.
7) PROFIT!
See:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.aspx[
^],
http://msdn.microsoft.com/en-us/library/3z132tat.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.drawing.imaging.pixelformat.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.aspx[
^].
(You see how much you will need?! :-))
—SA