用VB做图片浏览器如何实现顺时针旋转90度?

想做个图片浏览器,如何实现图片旋转的功能,给出一个顺时针旋转90度的代码就可以,自己对VB了解的太少,希望高手帮帮忙,谢谢........................... 想做个图片浏览器,如何实现图片旋转的功能,给出一个顺时针旋转90度的代码就可以,自己对VB了解的太少,希望高手帮帮忙,谢谢........................ 展开
 我来答
匿名用户
2013-10-12
展开全部
CTRL + V. 知道原理就好办, 其实就是用GetPixel拿指定角度的点的像素,然后用SetPixel输出到DC上你希望的角度位置,当然, 这其中得计算你希望输出的角度, 从而实现顺时针或逆时针转换.看代码吧, 复制来的.... Const SRCCOPY = &HCC0020
Const Pi = 3.14159265359
Private Declare Function SetPixel Lib "GDI32" (ByVal hDC As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal crColor As Long) As Long
Private Declare Function GetPixel Lib "GDI32" (ByVal hDC As Integer, ByVal X As Integer, ByVal Y As Integer) As Long
Private Declare Function StretchBlt% Lib "GDI32" (ByVal hDC%, ByVal X%, ByVal Y%, ByVal nWidth%, ByVal nHeight%, ByVal hSrcDC%, ByVal XSrc%, ByVal YSrc%, ByVal nSrcWidth%, ByVal nSrcHeight%, ByVal dwRop&)
Sub Form_Load()
Picture1.ScaleMode = 3
Picture2.ScaleMode = 3
End Sub
Sub Command1_Click()
'rotate Right 45 degrees
Picture2.Cls
Call bmp_rotate(Picture1, Picture2, -3.14 / 4)
End Sub
Sub Command2_Click()
'vertical convert
Picture2.Cls
px% = Picture1.ScaleWidth
py% = Picture1.ScaleHeight
retval% = StretchBlt(Picture2.hDC, 0, py%, px%, -py%, Picture1.hDC, 0, 0, px%, py%, SRCCOPY)
End Sub
Sub Command3_Click()
'rotate Left 45 degrees
Picture2.Cls
Call bmp_rotate(Picture1, Picture2, 3.14 / 4)
End Sub
Sub bmp_rotate(pic1 As PictureBox, pic2 As PictureBox, ByVal theta!)
' bmp_rotate(pic1, pic2, theta)
' Rotate the image in a picture box.
' pic1 is the picture box with the bitmap to rotate
' pic2 is the picture box to receive the rotated bitmap
' theta is the angle of rotation
Dim c1x As Integer, c1y As Integer
Dim c2x As Integer, c2y As Integer
Dim a As Single
Dim p1x As Integer, p1y As Integer
Dim p2x As Integer, p2y As Integer
Dim n As Integer
Dim r As Integer

c1x = pic1.ScaleWidth \ 2
c1y = pic1.ScaleHeight \ 2
c2x = pic2.ScaleWidth \ 2
c2y = pic2.ScaleHeight \ 2

If c2x < c2y Then n = c2y Else n = c2x
n = n - 1
pic1hDC% = pic1.hDC
pic2hDC% = pic2.hDC

For p2x = 0 To n
For p2y = 0 To n

If p2x = 0 Then a = Pi / 2 Else a = Atn(p2y / p2x)

r = Sqr(1& * p2x * p2x + 1& * p2y * p2y)
p1x = r * Cos(a + theta!)
p1y = r * Sin(a + theta!)
c0& = GetPixel(pic1hDC%, c1x + p1x, c1y + p1y)
c1& = GetPixel(pic1hDC%, c1x - p1x, c1y - p1y)
c2& = GetPixel(pic1hDC%, c1x + p1y, c1y - p1x)
c3& = GetPixel(pic1hDC%, c1x - p1y, c1y + p1x)

If c0& <> -1 Then xret& = SetPixel(pic2hDC%, c2x + p2x, c2y + p2y, c0&)
If c1& <> -1 Then xret& = SetPixel(pic2hDC%, c2x - p2x, c2y - p2y, c1&)
If c2& <> -1 Then xret& = SetPixel(pic2hDC%, c2x + p2y, c2y - p2x, c2&)
If c3& <> -1 Then xret& = SetPixel(pic2hDC%, c2x - p2y, c2y + p2x, c3&)
Next

t% = DoEvents()
Next
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式