请问如何在VB中使图片旋转???

Luo_Yong 2002-04-15 06:01:56
请问如何在VB中使图片旋转???
非常感谢!!!
...全文
241 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Luo_Yong 2002-04-15
  • 打赏
  • 举报
回复
感谢: xxlroad(土八路)
xxlroad 2002-04-15
  • 打赏
  • 举报
回复
http://www.csdn.net/expert/topic/614/614863.xml?temp=6.406802E-02
主  题: 如何使一个BMP的图象旋转任意角度,能告诉我一个具体算法吗?
作  者: spirit00 (精灵)
等  级:
信 誉 值: 97
所属论坛: Visual Basic
问题点数: 20
回复次数: 9
发表时间: 2002-4-1 17:02:54



如何使一个BMP的图象旋转任意角度,能告诉我一个具体算法吗?能写段代码吗?



Top

回复人: xxlroad(土八路) ( ) 信誉:100 2002-04-15 18:31:00 得分:0


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


xxlroad 2002-04-15
  • 打赏
  • 举报
回复
http://www.csdn.net/expert/topic/615/615433.xml?temp=9.777468E-02
主  题: 如何在Vb中实现图片的逆(顺)时针旋转?
作  者: liffree (飞雪)
等  级:
信 誉 值: 100
所属论坛: Visual Basic
问题点数: 50
回复次数: 6
发表时间: 2002-4-1 21:15:41
Luo_Yong 2002-04-15
  • 打赏
  • 举报
回复
搞没---------搞错!
一不小心,还没高手帮助贴子就到后面去了,嗯,我顶!!!

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧