要求添加个按钮 
功能: 点击让 
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 

解决方案 »

  1.   

    VB中位图旋转的实现在VISUAL BASIC中没有什么命令或函数能够实现将一个位图旋转一个角度后显示出来,但我们可以用画点的方式,将一个图画盒中的位图中的像素点旋转一个角度后画入另一个图画盒中,当源图画盒中的像素都被画到目标图画盒中时,也就完成了位图的旋转。这里主要用到了VISUAL BASIC中的两个方法:POINT方法和PSET方法。POINT方法的作用是从源图画盒中提取一个像素点的颜色值;而PSET方法的作用是按照旋转后的坐标和相应像素点的颜色值在目标图画盒中画点。显然这个方法的速度不会太快,因而适用于较小的图片。下面介绍一下实现方法:进入VISUAL BASIC中,建立一个新的窗体。在窗体中加入两个图画盒控件(Picture1和Picture2),设置它们的Name属性为PicSource和PicTarget,并为PicSource图画盒的Picture属性设置一幅位图。再在窗体中加入一个按钮(CommandRotorate),设置它的Caption属性为“旋转”。然后加入以下代码:
    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
      

  2.   

    http://www.vbaccelerator.com/home/VB/Code/vbMedia/Using_GDI_Plus/Scale__Rotate__Skew_and_Transform_Images/article.asp
      

  3.   

    http://www.m5home.com/blog/article.asp?id=354主要是PlgBlt函数使用,可实现任意角度旋转.