huatas 2005-3-19 12:33
在VB中使加载的图片按一定角度旋转除了用PlgBlt谁有更好的方法
如题
huatas 2005-3-21 13:10
那我就先谢拉,最近在做时钟,发现用PlgBlt旋转图形会有些变形,无法准确定位。
Nothing 2005-3-21 20:14
下面代码可以实现图片旋转,但速度不快.
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
Dim PI As Double
PI = 3.1415926
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