views:

63

answers:

5

In developing a flash-based memory manager, I need to be able to view large quantities of data. With my eyes and monitor resolution, I can read hand-drawn 3x5 letters on a 4x6 matrix without too much difficulty, but none of the system TrueType fonts render optimally at that size. I've tried writing code to draw font shapes to off-screen bitmaps, and then use DrawImage to copy those bitmaps to the screen, but I can't get good performance. This is for development, not production, so performance doesn't have to be absolutely optimal, but I don't want to spend too long waiting for screens of data to refresh.

What would be the best way of either making .net display a font which is pixel-perfect what I want, or else building a bitmap out of lots of little pieces quickly? I'm using vb.net, so I can't simply generate a bitmap as a byte array and pass that to the Bitmap constructor unless someone can show me how to convert an array into an IntPtr.

+1  A: 

I'd find an existing 3x5 pixel font, and use it to draw text. Would this work? http://www.pimpyourfont.com/font-12368-Pixelzim-3x5

Ned Batchelder
Can bitmap fonts be used within GDI+?
supercat
A: 

I'd use a font editor to put your individual bitmaps together into a bitmapped font, then display your text in that font.

Jerry Coffin
+2  A: 

I would suggest creating the font yourself. There are several good font editors out there:

Font Forge -- http://fontforge.sourceforge.net/

FontCreator -- http://www.high-logic.com/fontcreator.html

Type Light -- http://cr8.netfirms.com/typelight.html

TTFEdit -- http://sourceforge.net/projects/ttfedit/

DoubleType -- http://doubletype.org/wiki/index.php/DoubleType

icemanind
Do any of the above offer a nice quick way to convert a bitmap into a font (e.g. by grabbing characters at regular intervals)? Also, if I want to display text in multiple colors and I'm using a monospaced font, would I be best off making strings which contain a mixture of blanks and the data of interest in each color, or is there some better way?
supercat
Well if your using the .NET standard DrawString method, then it has a parameter for brush color. You can set the brush color to any color you want. If you are looking to make each letter in a string a different color, then you might want to take a look at my virtual machine tutorial: http://www.icemanind.com ..you can download the source code to my B32 machine. I have a class in there called B32Screen which does something similar to what you are trying to do. I basically created a bitmap, did all my work on the bitmap, then copied the bitmap to the screen..it works well
icemanind
@icemanind: That looks a lot like what I'm trying to do. At the moment my code keeps a cache of bitmaps for each little string I want to plot. Drawing 1,024 little 11x5 bitmaps from the cache seems to take about 200ms. What I'm after is to have an overview control which shows the status (blank, partially-written, full, or invalidated) of all 1024 flash blocks in the system, and allow the user to move the cursor around the overview control to see the contents of the current flash block (4096 bytes, with certain bytes hilighted).
supercat
+1  A: 

To draw readable text at that size you should consider subpixel rendering. Take a look at these examples.

Dour High Arch
A: 

My thanks to those who answered. I had been overcomplicating things in the hopes of improving responsiveness, but was just making things worse. I had separate routines to handle a change to an on-screen item and to handle screen redraws. For the each item I kept thee objects representing the current state, the state drawn on screen, and state drawn in a backing bitmap. When an item that had already been drawn on-screen changed, I would draw the changed version directly to the screen (using Control.CreateGraphics) without invalidating anything. When a portion of the screen was invalidated and needed to be redrawn, I would update the items on the backing bitmap and then copy the backing bitmap to the screen. My goal was to avoid copying the entire backing bitmap to the screen every time an item changed. My expectation was that screen redraws due to region invalidation would not generally be interspersed with item updates, and that updating an item by drawing to the screen would be faster than drawing to an off-screen bitmap and copying that to the screen.

Performance improved considerably when I made the item-changed code draw to the off-screen bitmap and invalidate the region containing the item. It seems there's a substantial per-drawing-operation penalty when copying bitmaps to the screen that does not exist when copying to another off-screen bitmap. Thus, copying twenty little bitmaps into pieces of a big one, invalidating the areas of the on-screen representation where those little bitmaps appear, and then copying the whole big bitmap to the screen (clipped to the invalidated areas) is much faster than simply throwing the little bitmaps on the screen.

supercat