旋转有一个极简单但是速度慢的做法。for j = 0 to 高 for i = 0 to 宽 p = point( i, j ) pset( j, i ), p next j next i
Option ExplicitPrivate Function xuanzhuan(ByVal fnt As String) As String Dim a(0 To 31) As Long Dim b(0 To 15, 0 To 15) As Long
Dim i As Long Dim j As Long Dim k As Long
fnt = Replace(fnt, " ", "") Dim l As Long
l = Len(fnt) l = Int(l / 2) * 2 '取整
Dim p As String
For i = 1 To l - 2 Step 2 p = Mid(fnt, i, 2) a(Int(i / 2)) = Val("&h" & p) Next i
Dim bit As Byte For i = 0 To 15 '16行 For j = 0 To 1 '每行2字节 For k = 7 To 0 Step -1 bit = a(i * 2 + j) \ (2 ^ k) '取出来一个bit,从高位开始取 bit = bit And 1 Debug.Print bit; '往b()里面放 If bit Then 'b(15 - (1 - j) * 8 - k, (15 - i)) = 1 '右转90度 b((1 - j) * 8 + k, i) = 1 '左转90度 End If Next k Next j Debug.Print Next i Debug.Print For i = 0 To 15 '16行 For j = 0 To 15 '16个 Debug.Print b(i, j); Next j Debug.Print Next i Debug.Print
Dim ss As String Dim tt As Long Dim r As String For i = 0 To 15 For j = 0 To 1 tt = 0 For k = 7 To 0 Step -1 If b(i, j * 8 + k) Then tt = tt Or 2 ^ k End If Next k If tt < 16 Then ss = ss & "0" & Hex$(tt) Else ss = ss & Hex$(tt) End If Next j 'Debug.Print Next i
xuanzhuan = ss End FunctionPrivate Sub Command1_Click() Dim s As String Dim i As Long
For i = 0 To 15 s = s & "F0" Next i For i = 0 To 15 s = s & "00" Next i 's = "F0F0..............0000" '旋转完应该是
Debug.Print xuanzhuan(s) End Sub
'添加 Picture1 Picture2 Text1 Command1Option Explicit Private Declare Function GetDesktopWindow Lib "user32" () As Long Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hdc As Long) As Long Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long Const Pi = 3.1415926 Dim i%, X%, Y%, X1%, Y1%, X2#, Y2#, X3#, y3#, JiaoDu#, HuDu#, hMemDc&, lngDesktopHwnd&, lngDesktopDC& Private Sub Form_Activate() Command1.Caption = "旋 转" '设置窗体属性并置中 Me.BorderStyle = 0 : Me.Caption = "" Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2 '设置 Picture1 属性 With Picture1 .ScaleMode = vbPixels .AutoRedraw = True .Width = Text1.Width .Height = Text1.Height .Left = Screen.Width End With '设置 Picture2 属性 With Picture2 .ScaleMode = vbPixels .AutoRedraw = True .Width = Text1.Width * 1.1 .Height = Text1.Width * 1.1 End With '设置 Text1 属性 With Text1 .BackColor = vbBlue .ForeColor = vbWhite .FontSize = 20 End With End SubPrivate Sub Command1_Click() '抓取 Text1的图片 lngDesktopHwnd = GetDesktopWindow lngDesktopDC = GetDC(lngDesktopHwnd) Call BitBlt(Picture1.hdc, 0, 0, Text1.Width, Text1.Height, lngDesktopDC, (Me.Left + Text1.Left) \ 15, (Me.Top + Text1.Top) \ 15, vbSrcCopy) Picture1.Picture = Picture1.Image '************** 开始旋转 *************** For i = 0 To 360 Step 5 DoEvents Picture2.Cls JiaoDu = i '旋转角度 If JiaoDu = 360 Then JiaoDu = 0 HuDu = JiaoDu * Pi / 180 'VB是以弧度来计算的,所以要先将角度转为弧度. For X = 0 To Picture2.ScaleWidth X1 = X - Picture2.ScaleWidth \ 2 For Y = 0 To Picture2.ScaleHeight Y1 = Y - Picture2.ScaleHeight \ 2 X2 = X1 * Cos(-HuDu) + Y1 * Sin(-HuDu) Y2 = Y1 * Cos(-HuDu) - X1 * Sin(-HuDu) X3 = X2 + Picture1.ScaleWidth \ 2 y3 = Y2 + Picture1.ScaleHeight \ 2 If X3 > 0 And X3 < Picture1.ScaleWidth - 1 And y3 > 0 And y3 < Picture1.ScaleHeight - 1 Then Picture2.PSet (X, Y), Picture1.Point(X3, y3) Next Y Next X Next i End Sub
[email protected]
Dim cBuf As String * 21000
Dim temp, temp1 As String
nCount = GETFONTHEX(txtpm.Text, "宋体", "chnstr02", 0, 30, 0, 1, 0, cBuf)
temp = Mid(cBuf, 1, nCount)nCount = GETFONTHEX(cmbdj.Text, "宋体", "chnstr01", 0, 30, 0, 1, 0, cBuf)
temp1 = Mid(cBuf, 1, nCount)Dim filehandle As Integer
Dim labelstring As Stringlabelstring = labelstring & "^XA"
labelstring = labelstring & "^CW1"
labelstring = labelstring & "^FWR"labelstring = labelstring & "^FO250,180^A0,40,40^FD" & txtXh.Text & "^FS"
labelstring = labelstring & "^FO350,180^A0,40,40^FD" & txtjz.Text & " Kg^FS"
labelstring = labelstring & "^FO450,180^A0,40,40^XGchnstr01,1,1^FS"
labelstring = labelstring & "^FO520,180^A0,40,40^FD" & cmbPh.Text & "^FS"
labelstring = labelstring & "^FO600,180^A0,40,40^FWR^XGchnstr02,1,1^FS"'打印图片labelstring = labelstring & "^FO350,630^A0,40,40^FD" & txtMz.Text & " Kg^FS"
labelstring = labelstring & "^FO450,630^A0,40,40^FD" & cmbTs.Text & "^FS"
labelstring = labelstring & "^FO520,630^A0,40,40^FD" & cmbNx.Text & "^FS"
labelstring = labelstring & "^FO600,630^A0,40,40^FD" & txtGg.Text & "^FS"
labelstring = labelstring & "^FO100,900^A0N^BY4^BIN,100,Y,N"
labelstring = labelstring & "^FD" & txtXh.Text & "^FS"
labelstring = labelstring & "^XZ"
'labelstring = "^XA^FO250,180^A0,40,40^FDABCEDE^FS^XZ"filehandle = FreeFile
'Open "LPT1 " For Output As filehandle
'Print #filehandle, labelstring
'Close filehandleOpen "LPT1:" For Binary Access Write As #1
Put #1, , temp
Put #1, , temp1
Put #1, , labelstring
Close #1
for i = 0 to 宽
p = point( i, j )
pset( j, i ), p
next j
next i
Dim a(0 To 31) As Long
Dim b(0 To 15, 0 To 15) As Long
Dim i As Long
Dim j As Long
Dim k As Long
fnt = Replace(fnt, " ", "")
Dim l As Long
l = Len(fnt)
l = Int(l / 2) * 2 '取整
Dim p As String
For i = 1 To l - 2 Step 2
p = Mid(fnt, i, 2)
a(Int(i / 2)) = Val("&h" & p)
Next i
Dim bit As Byte
For i = 0 To 15 '16行
For j = 0 To 1 '每行2字节
For k = 7 To 0 Step -1
bit = a(i * 2 + j) \ (2 ^ k) '取出来一个bit,从高位开始取
bit = bit And 1
Debug.Print bit;
'往b()里面放
If bit Then
'b(15 - (1 - j) * 8 - k, (15 - i)) = 1 '右转90度
b((1 - j) * 8 + k, i) = 1 '左转90度
End If
Next k
Next j
Debug.Print
Next i
Debug.Print
For i = 0 To 15 '16行
For j = 0 To 15 '16个
Debug.Print b(i, j);
Next j
Debug.Print
Next i
Debug.Print
Dim ss As String
Dim tt As Long
Dim r As String
For i = 0 To 15
For j = 0 To 1
tt = 0
For k = 7 To 0 Step -1
If b(i, j * 8 + k) Then
tt = tt Or 2 ^ k
End If
Next k
If tt < 16 Then
ss = ss & "0" & Hex$(tt)
Else
ss = ss & Hex$(tt)
End If
Next j
'Debug.Print
Next i
xuanzhuan = ss
End FunctionPrivate Sub Command1_Click()
Dim s As String
Dim i As Long
For i = 0 To 15
s = s & "F0"
Next i
For i = 0 To 15
s = s & "00"
Next i
's = "F0F0..............0000"
'旋转完应该是
Debug.Print xuanzhuan(s)
End Sub
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hdc As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Const Pi = 3.1415926
Dim i%, X%, Y%, X1%, Y1%, X2#, Y2#, X3#, y3#, JiaoDu#, HuDu#, hMemDc&, lngDesktopHwnd&, lngDesktopDC&
Private Sub Form_Activate()
Command1.Caption = "旋 转"
'设置窗体属性并置中
Me.BorderStyle = 0 : Me.Caption = ""
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
'设置 Picture1 属性
With Picture1
.ScaleMode = vbPixels
.AutoRedraw = True
.Width = Text1.Width
.Height = Text1.Height
.Left = Screen.Width
End With
'设置 Picture2 属性
With Picture2
.ScaleMode = vbPixels
.AutoRedraw = True
.Width = Text1.Width * 1.1
.Height = Text1.Width * 1.1
End With
'设置 Text1 属性
With Text1
.BackColor = vbBlue
.ForeColor = vbWhite
.FontSize = 20
End With
End SubPrivate Sub Command1_Click()
'抓取 Text1的图片
lngDesktopHwnd = GetDesktopWindow
lngDesktopDC = GetDC(lngDesktopHwnd)
Call BitBlt(Picture1.hdc, 0, 0, Text1.Width, Text1.Height, lngDesktopDC, (Me.Left + Text1.Left) \ 15, (Me.Top + Text1.Top) \ 15, vbSrcCopy)
Picture1.Picture = Picture1.Image
'************** 开始旋转 ***************
For i = 0 To 360 Step 5
DoEvents
Picture2.Cls
JiaoDu = i '旋转角度
If JiaoDu = 360 Then JiaoDu = 0
HuDu = JiaoDu * Pi / 180 'VB是以弧度来计算的,所以要先将角度转为弧度.
For X = 0 To Picture2.ScaleWidth
X1 = X - Picture2.ScaleWidth \ 2
For Y = 0 To Picture2.ScaleHeight
Y1 = Y - Picture2.ScaleHeight \ 2
X2 = X1 * Cos(-HuDu) + Y1 * Sin(-HuDu)
Y2 = Y1 * Cos(-HuDu) - X1 * Sin(-HuDu)
X3 = X2 + Picture1.ScaleWidth \ 2
y3 = Y2 + Picture1.ScaleHeight \ 2
If X3 > 0 And X3 < Picture1.ScaleWidth - 1 And y3 > 0 And y3 < Picture1.ScaleHeight - 1 Then Picture2.PSet (X, Y), Picture1.Point(X3, y3)
Next Y
Next X
Next i
End Sub
不用这个参数正常,该怎么办