要求添加个按钮
功能: 点击让
Picture1里的图片顺时针旋转90度,请大家帮帮忙啊 救救急。 Dim tempPicture As IPictureDisp Private Sub Command1_Click()
Dim path As String
path = "E:\project\TEMP\000.jpg" '图片不一定是JPG格式
' Picture1.Picture = LoadPicture(path)
Set tempPicture = LoadPicture(path)
PictureToCenter tempPicture, Picture1 End Sub Public Sub PictureToCenter(Pic As Picture, PicBox As PictureBox)
Dim PicH As Long, PicW As Long
Dim PicBoxW As Long, PicBoxH As Long
Dim PicRate As Single, PicBoxRate As Single
Dim NewH As Long, NewW As Long
If Not Pic Is Nothing Then
PicBoxH = PicBox.ScaleHeight
PicBoxW = PicBox.ScaleWidth
PicBoxRate = PicBoxW / PicBoxH
PicW = PicBox.ScaleX(Pic.Width, vbHimetric, vbTwips)
PicH = PicBox.ScaleY(Pic.Height, vbHimetric, vbTwips)
PicRate = PicW / PicH
' PicBox.Picture = Nothing
PicBox.Cls
If PicH <= PicBoxH And PicW <= PicBoxW Then
PicBox.PaintPicture Pic, (PicBoxW - PicW) / 2, (PicBoxH - PicH) / 2
Exit Sub
End If
If PicBoxRate < PicRate Then
NewH = PicBoxW / PicRate
PicBox.PaintPicture Pic, 0, (PicBoxH - NewH) / 2, PicBoxW, NewH
Else
NewW = PicBoxH * PicRate
PicBox.PaintPicture Pic, (PicBoxW - NewW) / 2, 0, NewW, PicBoxH
End If
' PicBox.Picture = Pic
End If
End Sub
功能: 点击让
Picture1里的图片顺时针旋转90度,请大家帮帮忙啊 救救急。 Dim tempPicture As IPictureDisp Private Sub Command1_Click()
Dim path As String
path = "E:\project\TEMP\000.jpg" '图片不一定是JPG格式
' Picture1.Picture = LoadPicture(path)
Set tempPicture = LoadPicture(path)
PictureToCenter tempPicture, Picture1 End Sub Public Sub PictureToCenter(Pic As Picture, PicBox As PictureBox)
Dim PicH As Long, PicW As Long
Dim PicBoxW As Long, PicBoxH As Long
Dim PicRate As Single, PicBoxRate As Single
Dim NewH As Long, NewW As Long
If Not Pic Is Nothing Then
PicBoxH = PicBox.ScaleHeight
PicBoxW = PicBox.ScaleWidth
PicBoxRate = PicBoxW / PicBoxH
PicW = PicBox.ScaleX(Pic.Width, vbHimetric, vbTwips)
PicH = PicBox.ScaleY(Pic.Height, vbHimetric, vbTwips)
PicRate = PicW / PicH
' PicBox.Picture = Nothing
PicBox.Cls
If PicH <= PicBoxH And PicW <= PicBoxW Then
PicBox.PaintPicture Pic, (PicBoxW - PicW) / 2, (PicBoxH - PicH) / 2
Exit Sub
End If
If PicBoxRate < PicRate Then
NewH = PicBoxW / PicRate
PicBox.PaintPicture Pic, 0, (PicBoxH - NewH) / 2, PicBoxW, NewH
Else
NewW = PicBoxH * PicRate
PicBox.PaintPicture Pic, (PicBoxW - NewW) / 2, 0, NewW, PicBoxH
End If
' PicBox.Picture = Pic
End If
End Sub
解决方案 »
- VB---为什么会出现“多步操作产生错误,请检查每一步状态值”?
- 现在程序中要同时处理两个数据库,该怎么写事物处理
- 急求vb---treeview实例,在线等,回答给分!!!
- 很简单的数组问题(送分了)
- vb安装后,听说会有一个文件夹中是示例源码,这个文件夹在何处?
- VB访问CSV文件,中文环境下开发,没有问题,但到了英文环境下运行的时候会报“odbc错误,期待参数是2”的错误
- 请教TextStream/FileSystemObject的问题
- √有哪位兄弟知道水晶报表9.0(Crystal)企业版中的那个Report Application Server (RAS)的密码是多少
- TREEVIEW简单问题
- 一个VB程序的几个问题
- 统计文本框里的所有字符
- 用VB怎么打开IE的历史对话框?
Option Explicit
Const Pi = 3.14
Private Sub CommandRototate_Click()
Dim x As Integer, y As Integer
Dim X1 As Integer, Y1 As Integer
Dim X2 As Double, Y2 As Double
Dim X3 As Double, Y3 As Double
Dim JiaoDu As Double
Dim HuDu As Double
JiaoDu = 45 '角度
HuDu = JiaoDu * Pi / 180 '弧度
PicSource.ScaleMode = vbPixels
PicTarget.ScaleMode = vbPixels
For x = 0 To PicTarget.ScaleWidth
X1 = x - PicTarget.ScaleWidth \ 2
For y = 0 To PicTarget.ScaleHeight
Y1 = y - PicTarget.ScaleHeight \ 2
X2 = X1 * Cos(-HuDu) + Y1 * Sin(-HuDu)
Y2 = Y1 * Cos(-HuDu) - X1 * Sin(-HuDu)
X3 = X2 + PicSource.ScaleWidth \ 2
Y3 = Y2 + PicSource.ScaleHeight \ 2
If X3 > 0 And X3 < PicSource.ScaleWidth - 1 And Y3 > 0 And Y3 <
PicSource.ScaleHeight - 1 Then
PicTarget.PSet (x, y), PicSource.Point(X3, Y3)
End If
Next y
Next x
End Sub
运行后,按下“旋转”按钮,可以见到源图画盒中的位图旋转45度后进入到目标图画盒中。如果要改变旋转的角度,只需将JiaoDu变量设置为相应值即可。来源: 芯友网 http://www.xy-365.com 详细点击:http://www.xy-365.com/company/s_1909.htm