Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Visual Basic 6 - ruotare un immagine
Forum - Visual Basic 6 - ruotare un immagine - Pagina 4

Pagine: [ 1 2 3 4 ] Precedente | Prossimo
Avatar
moet (Normal User)
Pro


Messaggi: 185
Iscritto: 13/11/2007

Segnala al moderatore
Postato alle 21:58
Giovedì, 22/11/2007
stesso errore mi dice separatore di elenco oppure )

PM Quote
Avatar
P4p3r0g4 (Member)
Guru


Messaggi: 1319
Iscritto: 29/12/2006

Segnala al moderatore
Postato alle 23:48
Giovedì, 22/11/2007
veramente c'è già nel codice.
rotate bitmap è una sub di base di msdn.

Codice sorgente - presumibilmente VB.NET

  1. Public Sub RotateBitmap(hBitmapDC As Long, lWidth As Long, _
  2.          lHeight As Long, lRadians As Long)
  3.  
  4.          Dim hNewBitmapDC As Long    ' DC of the new bitmap
  5.          Dim hNewBitmap As Long      ' handle to the new bitmap
  6.          Dim lSine As Long           ' sine used in rotation
  7.          Dim lCosine As Long         ' cosine used in rotation
  8.          Dim X1 As Long              ' used in calculating new
  9.                                      ' bitmap dimensions
  10.          Dim X2 As Long              ' used in calculating new
  11.                                      ' bitmap dimensions
  12.          Dim X3 As Long              ' used in calculating new
  13.                                      ' bitmap dimensions
  14.          Dim Y1 As Long              ' used in calculating new
  15.                                      ' bitmap dimensions
  16.          Dim Y2 As Long              ' used in calculating new
  17.                                      ' bitmap dimensions
  18.          Dim Y3 As Long              ' used in calculating new
  19.                                      ' bitmap dimensions
  20.          Dim lMinX As Long           ' used in calculating new
  21.                                      ' bitmap dimensions
  22.          Dim lMaxX As Long           ' used in calculating new
  23.                                      ' bitmap dimensions
  24.          Dim lMinY As Long           ' used in calculating new
  25.                                      ' bitmap dimensions
  26.          Dim lMaxY As Long           ' used in calculating new
  27.                                      ' bitmap dimensions
  28.          Dim lNewWidth As Long       ' width of new bitmap
  29.          Dim lNewHeight As Long      ' height of new bitmap
  30.          Dim I As Long               ' loop counter
  31.          Dim J As Long               ' loop counter
  32.          Dim lSourceX As Long        ' x pixel coord we are blitting
  33.                                      ' from the source  image
  34.          Dim lSourceY As Long        ' y pixel coord we are blitting
  35.                                      ' from the source image
  36.  
  37.          ' create a compatible DC from the one just brought
  38.          ' into this function
  39.          hNewBitmapDC = CreateCompatibleDC(hBitmapDC)
  40.  
  41.          ' compute the sine/cosinse of the radians used to
  42.          ' rotate this image
  43.          lSine = Sin(lRadians)
  44.          lCosine = Cos(lRadians)
  45.  
  46.          ' compute the size of the new bitmap being created
  47.          X1 = -lHeight * lSine
  48.          Y1 = lHeight * lCosine
  49.          X2 = lWidth * lCosine - lHeight * lSine
  50.          Y2 = lHeight * lCosine + lWidth * lSine
  51.          X3 = lWidth * lCosine
  52.          Y3 = lWidth * lSine
  53.  
  54.          ' figure out the max/min size of the new bitmap
  55.          lMinX = Min(0, Min(X1, Min(X2, X3)))
  56.          lMinY = Min(0, Min(Y1, Min(Y2, Y3)))
  57.          lMaxX = Max(X1, Max(X2, X3))
  58.          lMaxY = Max(Y1, Max(Y2, Y3))
  59.  
  60.          ' set the new bitmap width/height
  61.          lNewWidth = lMaxX - lMinX
  62.          lNewHeight = lMaxY - lMinY
  63.  
  64.          ' create a new bitmap based upon the new width/height of the
  65.          ' rotated bitmap
  66.          hNewBitmap = CreateCompatibleBitmap _
  67.          (hBitmapDC, lNewWidth, lNewHeight)
  68.  
  69.          ' attach the new bitmap to the new device context created
  70.          ' above before constructing the rotated bitmap
  71.          Call SelectObject(hNewBitmapDC, hNewBitmap)
  72.  
  73.          ' loop through and translate each pixel to its new location.
  74.          ' this is using a standard rotation algorithm
  75.          For I = 0 To lNewHeight
  76.             For J = 0 To lNewWidth
  77.                lSourceX = (J + lMinX) * lCosine + (I + lMinY) * lSine
  78.                lSourceY = (I + lMinY) * lCosine - (J + lMinX) * lSine
  79.                If (lSourceX >= 0) And (lSourceX <= lWidth) And _
  80.                (lSourceY >= 0) And (lSourceY <= lHeight) Then
  81.                   Call BitBlt(hNewBitmapDC, J, I, 1, 1, hBitmapDC, _
  82.                               lSourceX, lSourceY, SRCCOPY)
  83.                End If
  84.             Next J
  85.          Next I
  86.  
  87.          ' reset the new bitmap width and height
  88.          lWidth = lNewWidth
  89.          lHeight = lNewHeight
  90.  
  91.          ' return the DC to the new bitmap
  92.          hBitmapDC = hNewBitmapDC
  93.  
  94.          ' destroy the bitmap created
  95.          Call DeleteObject(hNewBitmap)
  96.  
  97.       End Sub


Ultima modifica effettuata da P4p3r0g4 il 22/11/2007 alle 23:49
PM Quote
Pagine: [ 1 2 3 4 ] Precedente | Prossimo