Newsgroup: it.comp.lang.visual-basic
Titolo: [?] Rotazione sull'asse di controllo Image

Come da oggetto
Mi spiego meglio
Sul form ho un oggetto Image che voglio far ruotare sul proprio asse in
funzione di una variabile
Non ho trovato nulla chi mi puň aiutare?
Ciao
JKLJKL :-)

 JKLJKL :-)
Vedi se questa funzione fa al caso tuo
Const Pi = 3.
14159265359
Const ScrCopy = &HCC0020
Dim Param As String
Private Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal X
As Long, ByVal Y As Long, ByVal crColor As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As
Long, ByVal Y As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal X
As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal
hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As
Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Sub bmp_rotate(ByVal theta!, Pre As Boolean)
    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, r As Integer
    Dim pic1hDc As Long, pic2hDc As Long
    If Not Pre Then
        c1x = Picture1.ScaleWidth \ 2
        c1y = Picture1.ScaleHeight \ 2
        Picture2.Height = Sqr(Picture1.Width ^ 2 + Picture1.Height ^ 2)
        Picture2.Width = Sqr(Picture1.Width ^ 2 + Picture1.Height ^ 2)
        DoEvents
        c2x = Picture2.ScaleWidth \ 2
        c2y = Picture2.ScaleHeight \ 2
        If c2x < c2y Then
            n = c2y
        Else
            n = c2x
        End If
        n = n - 1
        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(Picture1.hdc, c1x + p1x, c1y + p1y)
                c1& = GetPixel(Picture1.hdc, c1x - p1x, c1y - p1y)
                c2& = GetPixel(Picture1.hdc, c1x + p1y, c1y - p1x)
                c3& = GetPixel(Picture1.hdc, c1x - p1y, c1y + p1x)
                If c0& <> -1 Then xret& = SetPixelV(Picture2.hdc, c2x + p2x,
c2y + p2y, c0&)
                If c1& <> -1 Then xret& = SetPixelV(Picture2.hdc, c2x - p2x,
c2y - p2y, c1&)
                If c2& <> -1 Then xret& = SetPixelV(Picture2.hdc, c2x + p2y,
c2y - p2x, c2&)
                If c3& <> -1 Then xret& = SetPixelV(Picture2.hdc, c2x - p2y,
c2y + p2x, c3&)
            Next
            lblEsecuzione.Caption = "Esecuzione " & Int((p2x / n) * 100) &
"%"
            DoEvents
        Next
        Picture2.Refresh
        DoEvents
        SavePicture Picture2.Image, Param
    Else    'Preview
        If optBassa.Value Then
            pctPreview1.Width = imgPreview.Width / 2
            pctPreview1.Height = imgPreview.Height / 2
        Else
            If optMedia.Value Then
                pctPreview1.Width = imgPreview.Width / 1
                pctPreview1.Height = imgPreview.Height / 1
            Else
                pctPreview1.Width = imgPreview.Width / 0.5
                pctPreview1.Height = imgPreview.Height / 0.5
            End If
        End If
        DoEvents
        StretchBlt pctPreview1.hdc, 0, 0, pctPreview1.Width,
pctPreview1.Height, Picture1.hdc, 0, 0, Picture1.Width, Picture1.Height,
ScrCopy
        pctPreview1.Refresh
        SavePicture pctPreview1.Image, "T.bmp"
        pctPreview1.Picture = LoadPicture()
        pctPreview1.Refresh
        DoEvents
        pctPreview1.Picture = LoadPicture("T.bmp")
        DoEvents
        c1x = pctPreview1.ScaleWidth \ 1.5
        c1y = pctPreview1.ScaleHeight \ 1.5
        pctPreview2.Picture = LoadPicture()
        pctPreview2.Height = Sqr(pctPreview1.Width ^ 2 + pctPreview1.Height
^ 2)
        pctPreview2.Width = Sqr(pctPreview1.Width ^ 2 + pctPreview1.Height ^
2)
        DoEvents
        c2x = pctPreview2.ScaleWidth \ 2
        c2y = pctPreview2.ScaleHeight \ 2
        If c2x < c2y Then
            n = c2y
        Else
            n = c2x
        End If
        n = n - 1
        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(pctPreview1.hdc, c1x + p1x, c1y + p1y)
                c1& = GetPixel(pctPreview1.hdc, c1x - p1x, c1y - p1y)
                c2& = GetPixel(pctPreview1.hdc, c1x + p1y, c1y - p1x)
                c3& = GetPixel(pctPreview1.hdc, c1x - p1y, c1y + p1x)
                If c0& <> -1 Then xret& = SetPixelV(pctPreview2.hdc, c2x +
p2x, c2y + p2y, c0&)
                If c1& <> -1 Then xret& = SetPixelV(pctPreview2.hdc, c2x -
p2x, c2y - p2y, c1&)
                If c2& <> -1 Then xret& = SetPixelV(pctPreview2.hdc, c2x +
p2y, c2y - p2x, c2&)
                If c3& <> -1 Then xret& = SetPixelV(pctPreview2.hdc, c2x -
p2y, c2y + p2x, c3&)
            Next
            lblEsecuzione.Caption = "Esecuzione " & Int((p2x / n) * 100) &
"%"
            DoEvents
        Next
        pctPreview2.Refresh
        DoEvents
        SavePicture pctPreview2.Image, "T.bmp"
        imgPreview.Picture = LoadPicture("T.bmp")
        Kill "T.bmp"
        imgPreview.Refresh
    End If
End Sub
Ciao
    Sharkman