7,765
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Private Sub Command1_Click()
Dim X As Integer, Y As Integer, B As Double, C As Integer, M As Integer
If IsNumeric(TxtK.Text) = False Then Exit Sub
If IsNumeric(TxtG.Text) = False Then Exit Sub
Picture1.Width = Picture1.ScaleX(CInt(TxtK.Text), vbPixels, Picture1.ScaleMode) '定义 宽
Picture1.Height = Picture1.ScaleY(CInt(TxtG.Text), vbPixels, Picture1.ScaleMode) '定义 高
Picture1.BackColor = vbGreen
Picture1.Cls
Picture1.CurrentX = (Picture1.Width - Picture1.TextWidth(TxtC.Text)) / 2
Picture1.CurrentY = (Picture1.Height - Picture1.TextHeight(TxtC.Text)) / 2
Picture1.Print TxtC.Text
C = 0
B = 0
TxtR.Text = ""
'从左到右(X) 从下到上(Y)纵向取点
For X = 0 To CInt(TxtK.Text) - 1 '从左到右
For Y = CInt(TxtG.Text) - 1 To 0 Step -1 '从下到上
'每点,取色,对比
If Picture1.Point(Picture1.ScaleX(X, vbPixels, Picture1.ScaleMode), Picture1.ScaleY(Y, vbPixels, Picture1.ScaleMode)) = Picture1.BackColor Then
B = B Or 1 '为背景色,置位 低电平点亮LED(根据硬件设计)
End If
C = C + 1 '累计取点数量
If C = 16 Then '集满两个字节(16位),显示
M = M + 1
If B = 0 Then
If M = 16 Then
TxtR.Text = TxtR.Text & "0x0000"
C = 0
B = 0
Else
TxtR.Text = TxtR.Text & "0x0000" & ","
C = 0
B = 0
End If
End If
If B < 16 And B <> 0 Then
If M = 16 Then
TxtR.Text = TxtR.Text & "0x000" & Hex(B)
C = 0
B = 0
Else
TxtR.Text = TxtR.Text & "0x000" & Hex(B) & ","
C = 0
B = 0
End If
End If
If B < 256 And B >= 16 Then
If M = 16 Then
TxtR.Text = TxtR.Text & "0x00" & Hex(B)
C = 0
B = 0
Else
TxtR.Text = TxtR.Text & "0x00" & Hex(B) & ","
C = 0
B = 0
End If
End If
If B < 4096 And B >= 256 Then
If M = 16 Then
TxtR.Text = TxtR.Text & "0x0" & Hex(B)
C = 0
B = 0
Else
TxtR.Text = TxtR.Text & "0x0" & Hex(B) & ","
C = 0
B = 0
End If
End If
If B <= 65535 And B >= 4096 Then
If M = 16 Then
TxtR.Text = TxtR.Text & "0x" & Hex(B)
C = 0
B = 0
Else
TxtR.Text = TxtR.Text & "0x" & Hex(B) & ","
C = 0
B = 0
End If
End If
Else '不满两个字节(16位),进位
B = B * 2
End If
Next
Next
End Sub
Private Sub Form_Load()
TxtK.Text = "16"
TxtG.Text = "16"
End Sub