使用计算机字体的LED矩阵显示 [英] LED matrix display using computer Fonts

查看:118
本文介绍了使用计算机字体的LED矩阵显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是电子嵌入式工程师.我正在执行移动消息"显示,因此我需要开发一个软件.

矩阵中排列有20x20 Led.当用户选择任何已安装的计算机字体并在键盘上键入字母时.该字母应显示,并且还应显示与其相关的代码.

如果键入字母是A

xxxxxxiiiiiiiixxxxxx
xxxxxiiiixxiiiixxxxx
xxxxiiiixxxxiiiixxxx
xxxiiiixxxxxxiiiixxx
xxiiiixxxxxxxxiiiixx
xiiiixxxxxxxxxxiiiix
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii
iiiiiiiiiiiiiiiiiiii
iiiiiiiiiiiiiiiiiiii
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii

应该生成这样的代码图,其中i =导通,x =导通

有人可以帮我吗!!!!!!!!!!!!

I am Electronics Embedded Engineer. I Doing a Moving message display and i need to develop a software.

there are 20x20 Led arranged in a matrix. when a user selects any installed computer Fonts and type a letter in the keyboard. the letter should be displayed and a code related to it should also be displayed.

if typed a letter is A

xxxxxxiiiiiiiixxxxxx
xxxxxiiiixxiiiixxxxx
xxxxiiiixxxxiiiixxxx
xxxiiiixxxxxxiiiixxx
xxiiiixxxxxxxxiiiixx
xiiiixxxxxxxxxxiiiix
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii
iiiiiiiiiiiiiiiiiiii
iiiiiiiiiiiiiiiiiiii
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii
iiiixxxxxxxxxxxxiiii

such a code map should be generated where i = led on, x = led off

Can Anybody Help me please!!!!!!!!!!!!

推荐答案

那真的,真的很困难.问题在于某些字符无法放入20x20的矩阵中.例如,在英语中,根据字体的不同,有些字符带有"descenders":"gjpqy",有时还包括"z".这些降序是必需的,因为如果没有它们,大多数字体"a"和"q"看起来都是相同的.此外,在某些字体中,诸如"Q"之类的字符在基准线以下.因此,您的矩阵不再是20x20,而是20x14左右.幸运的是,这为按比例隔开的字符提供了足够的空间:"I"比"W"窄,但是它们都适合,因为您丢失了太多的高度. (您可能必须在顶部放一些字符以允许带重音符号-不确定).

这太讨厌了-非常讨厌-当以低像素分辨率自动绘制它们时使字符看起来特别困难,因为Windows内置的字体引擎不仅仅像LED一样以黑白方式工作'' s做到了:它们以灰色阴影显示(以证明需要对此页面进行抓屏并放大Paint中的文本)

更好的解决方案是自己设计固定高度的字符集,并显示这些字符集-这是PITA和许多枯燥的手工破坏工作,但这确实是获得良好字符形状的最佳方法.我应该知道,这些年来我已经做过太多次了...:笑:(在您问之前,不,我不能给您发送字体!)
That is really, really difficult. The problem is that some characters don''t fit into a 20x20 matrix. For example, in English, there are some characters with "descenders": "gjpqy" and sometimes "z" depending on teh font. These descenders are necessary, because without them, in most fonts ''a'' and ''q'' look identical. In addition, in some fonts characters like ''Q'' have a portion below the baseline. So, your matrix is no longer 20x20, it''s 20x14 or so. Fortunately, this provides ample space for proportionally spaced characters: ''I'' is narrower than ''W'', but they should both fit because you have lost so much height. (You may have to loose some at the top to allow for accented characters as well - not sure).

It''s nasty - very nasty - and making the characters look good when you automatically draw them at low pixcel resolutions is especially difficult, because the font engines built into Windows don''t just work in black and white, like LED''s do: they work in shades of grey (To prove it take a screen shot of this page, and zoom in on text in Paint)

A much, much better solution is to design fixed height character sets yourself, and display those - it''s a PITA and a lot of dull hand-destroying work, but it''s really is the best way to get nice character shapes. I should know, I''ve done it far too many times over the years...:laugh: (And before you ask, no I can''t send you the fonts!)


这里是个主意:

1)使用类System.Drawing.Bitmap,使用构造函数Bitmap(Int32, Int32, PixelFormat)创建一个实例.对于PixelFormat,使用System.Drawing.Imaging.PixelFormat.Format1bppIndexed具有最小的1位黑白格式.将位图的大小设置为20x20.

2)使用位图的实例作为参数,使用其静态工厂方法System.Drawing.Graphics.FromImage获取System.Drawing.Graphics的实例.

3)使用System.Drawing.Graphics的实例,使用System.Drawing.Graphics.DrawString方法之一在位图上绘制文本. 这是一个微妙的步骤:您需要选择适当的字体(可能是等宽字体),其大小和位置,以使字符适合您的20x20矩阵并正确定位(例如居中).一些较小的实验会有所帮助. 要找到一个适用于如此小的矩阵的字体将是一个挑战,但我相信这是可能的.在旧的文本模式PC程序中,我曾经使用甚至更小的矩阵.

4)不要忘记处理System.Drawing.Graphics的实例.最好在"using"语句下声明和使用实例.关于System.Drawing.Bitmap的实例也是一样.请参阅 http://msdn.microsoft.com/en-us/library /yh598w02%28v=VS.100%29.aspx [ http://msdn.microsoft.com/en-us/library/5ey6h79d. aspx [ ^ ],但不要忘记每个像素只有一位.

6)使用位图位数组和bmpData.Stride(请参见上面引用的代码示例)来寻址物理矩阵上的位.

7)利润!

参见:
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 [ ^ ].

(您知道需要多少吗?!:-))

—SA
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


这篇关于使用计算机字体的LED矩阵显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆