刚刚写的 粘贴到“记事本”,保存为“Form1.frm”VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 3090 ClientLeft = 60 ClientTop = 450 ClientWidth = 4680 LinkTopic = "Form1" ScaleHeight = 3090 ScaleWidth = 4680 StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton Command1 Caption = "Command1" Height = 645 Left = 810 TabIndex = 1 Top = 360 Width = 1275 End Begin VB.PictureBox Pic1 AutoRedraw = -1 'True BackColor = &H00000000& BeginProperty Font Name = "宋体" Size = 12 Charset = 134 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H00FFFFFF& Height = 1095 Left = 1020 ScaleHeight = 1035 ScaleWidth = 1365 TabIndex = 0 Top = 1830 Width = 1425 End Begin VB.Label Label1 AutoSize = -1 'True Caption = "Label1" Height = 180 Left = 2340 TabIndex = 2 Top = 450 Width = 540 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option ExplicitPrivate BitMapMask8(0 To 7) As BytePrivate Sub Command1_Click() Dim hF As Integer hF = FreeFile Open App.Path & "\HZ.dat" For Binary As hF
Me.MousePointer = 11 Command1.Enabled = False
Dim FW As Long, FH As Long Pic1.ScaleMode = vbPixels FW = Pic1.TextWidth("啊") FH = Pic1.TextHeight("啊")
Dim I As Long, J As Long Dim X As Long, Y As Long Dim MyText(0 To 1) As Byte Dim TempByte As Byte Dim BitPos As Long For I = 1 To 87 '区 MyText(0) = &HA0 + I For J = 1 To 94 '位 MyText(1) = &HA0 + J Pic1.Line (0, 0)-(FW, FH), vbBlack, BF Pic1.CurrentX = 0 Pic1.CurrentY = 0 Pic1.Print StrConv(MyText, vbUnicode) 'Pic1.Refresh For Y = 0 To FH - 1 TempByte = 0 BitPos = 0 For X = 0 To FW - 1 TempByte = TempByte Or BitMapMask8(BitPos) And Pic1.Point(X, Y) BitPos = BitPos + 1 If BitPos = 8 Then Put hF, , TempByte TempByte = 0 BitPos = 0 End If Next X If BitPos Then Put hF, , TempByte End If Next Y Next J Label1.Caption = I & "/87" DoEvents Next I
Close hF
Command1.Enabled = True Me.MousePointer = 0
End SubPrivate Sub Form_Load() Dim I As Long For I = 0 To 7 BitMapMask8(I) = 2 ^ (7 - I) Next I
End Sub
zyl910(910:分儿,我又来了!) 你太强了,佩服佩服不过我还有一个问题,我想自己控制自定义字模中字体的大小.我主要想要8x8,11x11,12x12,14x14的字,我知道宋体9号字是11X11的,不知你给的程序里在哪里可以改变Picture1的显示字体 是这两句么? FW = Pic1.TextWidth("啊") FH = Pic1.TextHeight("啊") 改成什么才行呢多谢SupermanKing我的显示程序已经完成 是11x11的单色字库显示Public Function viewFont(x As Integer, y As Integer, idx As Long, fieldPath As String) 'x和y是字模在窗体上的位置,idx是字模在字库中的位置(自定义编码) 'On Error Resume Next If Dir(fieldPath) = "" Then Exit Function Dim dat(21) As Byte Open fieldPath For Binary As #1 Get #1, 1 + idx * 22, dat Close #1 For yy = 0 To 21 Step 2 aaa = dat(yy + 1) For xx = 0 To 22 col = Int(aaa / 128) * 255 Form1.PSet (x + xx, y + yy / 2), RGB(col, col, col) aaa = (aaa Mod 128) * 2 Next xx aaa = dat(yy) For xx = 0 To 22 col = Int(aaa / 128) * 255 Form1.PSet (x + xx + 8, y + yy / 2), RGB(col, col, col) aaa = (aaa Mod 128) * 2 Next xx Next yy DoEvents Close #1 End Function
我曾在DOS下编写过一个位图显示程序,不过也就是256色的东西。
如果你想的只是在DOS下显示字体,而专门为这些字体作一个字体库的话,就是在简单不过的了。你可以直接使用那些字库文件(当然要懂得字库格式)。
如果你想做自己的字库文件,我也可以提供一些建议和方法:
在一般的要求中可以只为字库提供一种大小的字体。常用的是16*16
我们就已16*16的字体大小为标准来讨论吧。
你可以在VB中建立一个PictureBox控件作为获得字体的图形设备。
将PictureBox的Width和Height设置为16*15,16*15的大小。
因为字体的显示可以用"黑"、"白"来表示,所以我们可以将这些信息以二进制的方式表示。
因为字体的宽度为16,也就是说需要16位的二进制数(双子节)才可以存储一行的信息
要存储一个字的全部图像折需要32个字节的大小。举个例子:□□□■■■■■■■■■■■□□
□□□■□□□□■□□□□■□□
□□□■□□■■■■■□□■□□
□□□■□□□□■□□□□■□□
□□□■□□□□■□□□□■□□
□□□■□■■■■■■■□■□□
□□□■□□□□□□□□□■□□
□□□■□□■■■■■□□■□□
□□□■□□■□□□■□□■□□
□□□■□□■□□□■□□■□□
□□□■□□■■■■■□□■□□
□□■□□□■□□□■□□■□□
□□■□□□□□□□□□□■□□
□■□□□□□□□□□■□■□□
■□□□□□□□□□□□■□□□
□□□□□□□□□□□□□□□□上面是一个16*16的“周”字,我们看第一行,有16个点,我们可以用二进制来表示:
二进制数=0001111111111100 ("□□□■■■■■■■■■■■□□")
16进制数=&H1FFC
十进制数=8188
从16进制的数字可以看出 1F FC 是两个字节就可以存储一行的图形数据了
用16个双字节就可一存储1个字的图像了然后当我们要存储数据位置时可以按照字体的区位码来存储,具体方法如下:
首先获得汉字的区位码,用 区位码*(16*2) 就得到图像数据存储的位置,今后调用的时候也可以采用这方法取得图像数据存储的位置,直接定义好数组大小
Dim 数组(1 to 16) as Integer
用个:
Open ...
...
Get #?,?,数组()
就可以得到一个字的图形数据了其实这种方式和BMP的单色位图的存储方式是差不多的,只是没有文件头信息和一些细节不一样。自己研究一下吧。
再写个循环,用Point函数读取某点的颜色值,并进行位运算合并就这样简单
粘贴到“记事本”,保存为“Form1.frm”VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 645
Left = 810
TabIndex = 1
Top = 360
Width = 1275
End
Begin VB.PictureBox Pic1
AutoRedraw = -1 'True
BackColor = &H00000000&
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FFFFFF&
Height = 1095
Left = 1020
ScaleHeight = 1035
ScaleWidth = 1365
TabIndex = 0
Top = 1830
Width = 1425
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Label1"
Height = 180
Left = 2340
TabIndex = 2
Top = 450
Width = 540
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option ExplicitPrivate BitMapMask8(0 To 7) As BytePrivate Sub Command1_Click()
Dim hF As Integer
hF = FreeFile
Open App.Path & "\HZ.dat" For Binary As hF
Me.MousePointer = 11
Command1.Enabled = False
Dim FW As Long, FH As Long
Pic1.ScaleMode = vbPixels
FW = Pic1.TextWidth("啊")
FH = Pic1.TextHeight("啊")
Dim I As Long, J As Long
Dim X As Long, Y As Long
Dim MyText(0 To 1) As Byte
Dim TempByte As Byte
Dim BitPos As Long
For I = 1 To 87 '区
MyText(0) = &HA0 + I
For J = 1 To 94 '位
MyText(1) = &HA0 + J
Pic1.Line (0, 0)-(FW, FH), vbBlack, BF
Pic1.CurrentX = 0
Pic1.CurrentY = 0
Pic1.Print StrConv(MyText, vbUnicode)
'Pic1.Refresh
For Y = 0 To FH - 1
TempByte = 0
BitPos = 0
For X = 0 To FW - 1
TempByte = TempByte Or BitMapMask8(BitPos) And Pic1.Point(X, Y)
BitPos = BitPos + 1
If BitPos = 8 Then
Put hF, , TempByte
TempByte = 0
BitPos = 0
End If
Next X
If BitPos Then
Put hF, , TempByte
End If
Next Y
Next J
Label1.Caption = I & "/87"
DoEvents
Next I
Close hF
Command1.Enabled = True
Me.MousePointer = 0
End SubPrivate Sub Form_Load()
Dim I As Long
For I = 0 To 7
BitMapMask8(I) = 2 ^ (7 - I)
Next I
End Sub
是这两句么?
FW = Pic1.TextWidth("啊")
FH = Pic1.TextHeight("啊")
改成什么才行呢多谢SupermanKing我的显示程序已经完成
是11x11的单色字库显示Public Function viewFont(x As Integer, y As Integer, idx As Long, fieldPath As String)
'x和y是字模在窗体上的位置,idx是字模在字库中的位置(自定义编码)
'On Error Resume Next
If Dir(fieldPath) = "" Then Exit Function
Dim dat(21) As Byte
Open fieldPath For Binary As #1
Get #1, 1 + idx * 22, dat
Close #1
For yy = 0 To 21 Step 2
aaa = dat(yy + 1)
For xx = 0 To 22
col = Int(aaa / 128) * 255
Form1.PSet (x + xx, y + yy / 2), RGB(col, col, col)
aaa = (aaa Mod 128) * 2
Next xx
aaa = dat(yy)
For xx = 0 To 22
col = Int(aaa / 128) * 255
Form1.PSet (x + xx + 8, y + yy / 2), RGB(col, col, col)
aaa = (aaa Mod 128) * 2
Next xx
Next yy
DoEvents
Close #1
End Function
Pic1.Font.Size= 字模大小 * Screen.TwipsPerPixelY / 20
假如字模是8*8的:
Pic1.Font.Size= 12 * Screen.TwipsPerPixelY / 20