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 2

Pagine: [ 1 2 3 4 ] Precedente | Prossimo
Avatar
gius (Ex-Member)
Expert


Messaggi: 294
Iscritto: 20/06/2007

Segnala al moderatore
Postato alle 21:13
Venerdì, 16/11/2007
Di niente!!! :rotfl::rotfl:é sempre un piacere aiutare gli altri:D:D
P.S.Se ci sono prob postami;);)

PM Quote
Avatar
moet (Normal User)
Pro


Messaggi: 185
Iscritto: 13/11/2007

Segnala al moderatore
Postato alle 21:22
Venerdì, 16/11/2007
Mi da errore sul picture1.clear !!!!!!!

e l immagine gira di 90 ma all' impazzata!!!

non si ferma a 90, 180 , 270 , 0

PM Quote
Avatar
gius (Ex-Member)
Expert


Messaggi: 294
Iscritto: 20/06/2007

Segnala al moderatore
Postato alle 21:36
Venerdì, 16/11/2007
Scusa,leva il picture1.clear per l'altro non sò come fare;)

Ultima modifica effettuata da gius il 16/11/2007 alle 21:37
PM Quote
Avatar
P4p3r0g4 (Member)
Guru


Messaggi: 1319
Iscritto: 29/12/2006

Segnala al moderatore
Postato alle 22:21
Venerdì, 16/11/2007
Codice sorgente - presumibilmente VB.NET

  1. Public Sub rotateimage()
  2. Dim x As Integer
  3. Dim x As Long
  4. Dim y As Long
  5. Picture2.Height = Picture1.Width
  6. Picture2.Width = Picture1.Height
  7. For x = 0 To Picture1.Width
  8. For y = 0 To Picture1.Height
  9. Call SetPixel(Picture2.hdc, _
  10. y, x, GetPixel(Picture1.hdc, x, y))
  11. Next
  12. If x Mod 50 = 0 Then
  13. DoEvents
  14. Picture2.Refresh
  15. End If
  16. Next
  17. DoEvents
  18. Picture2.Refresh
  19. Picture1.Clear
  20. Picture1.Visible = False
  21. End Sub



questo codice ha una Alta densità di errori. o di cose che sinceramente eviterei di fare

Codice sorgente - presumibilmente VB.NET

  1. [b]Public Sub rotateimage()[/b] 'vedi fondo post
  2. [b]Dim x As Integer[/b] 'doppia dichiarazione,giusto long
  3. Dim x As Long
  4. Dim y As Long
  5. Picture2.Height = Picture1.Width
  6. Picture2.Width = Picture1.Height
  7. For x = 0 To Picture1.Width
  8. For y = 0 To Picture1.Height
  9. Call SetPixel(Picture2.hdc, y, x, GetPixel(Picture1.hdc, x, y))
  10. [b]Next[/b]' specifica cosa nei cicli annidati se no ti perdi
  11. [b]If x Mod 50 = 0 Then
  12. DoEvents
  13. Picture2.Refresh
  14. End If[/b] 'bizzarro metodo ma carino
  15. [b]Next[/b] 'vedi 2 commenti fa
  16. DoEvents
  17. Picture2.Refresh
  18. [b]Picture1.Clear
  19. Picture1.Visible = False[/b] ' questi non li ho proprio capiti...
  20. End Sub



consiglio di fare piuttosto una sub con un'argomento. così si crea una sub generica e con minore possibilità di errori per oggetti mal associati

private sub rotateimage(image as picturebox)
..
end sub

creerei anche la seconda picturebox da codice invece di improvvisarla già fatta.

[edit] manca anche la "pulizia" della picture 2 all'inizio del codice e il trasporto di immagine alla fine..[/edit]


Ps: moet, dove l'hai messo il "call rotateimage"?
in un command?

Ultima modifica effettuata da P4p3r0g4 il 16/11/2007 alle 22:28
PM Quote
Avatar
moet (Normal User)
Pro


Messaggi: 185
Iscritto: 13/11/2007

Segnala al moderatore
Postato alle 22:33
Venerdì, 16/11/2007
L ho provato con un command si  

PM Quote
Avatar
moet (Normal User)
Pro


Messaggi: 185
Iscritto: 13/11/2007

Segnala al moderatore
Postato alle 22:35
Venerdì, 16/11/2007
Non pensavo che per girare un immagine c era tutto sto lavoro !  :D

Si per ora non funziona...

PM Quote
Avatar
moet (Normal User)
Pro


Messaggi: 185
Iscritto: 13/11/2007

Segnala al moderatore
Postato alle 14:37
Mercoledì, 21/11/2007
Nessuna news ? :)

PM Quote
Avatar
gius (Ex-Member)
Expert


Messaggi: 294
Iscritto: 20/06/2007

Segnala al moderatore
Postato alle 22:33
Mercoledì, 21/11/2007
Questo funz l'ho testato

Sempre 2 picture con la proprieta AutoRedraw su True

Nel Form_Load

Codice sorgente - presumibilmente VB.NET

  1. Dim hRotatedBitmapDC As Long    
  2. Dim lWidth As Long                      
  3. Dim lHeight As Long            
  4. Dim lRadians As Long
  5. Dim sFileName As String    
  6. Dim hBitmap As Long              
  7. Dim lBMDC As Long                
  8. Dim sBitmapInfo As BITMAP  
  9. Dim Degrees As Long  
  10. Degrees = 0
  11. sFileName = "filename.bmp"
  12. hBitmap = LoadImage(0, sFileName, IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
  13.  If (hBitmap = 0) Then
  14. MsgBox "Error, Unable To Load Bitmap", vbOKOnly,"Bitmap Load Error"
  15. End
  16. End If
  17. lBMDC = CreateCompatibleDC(0)
  18. If (lBMDC = 0) Then
  19. MsgBox "Error, Unable To Create Device Context",
  20. vbOKOnly, "Device Context Error"
  21. Exit Sub
  22. End If
  23. Call SelectObject(lBMDC, hBitmap)
  24. Call GetObject(hBitmap, Len(sBitmapInfo), sBitmapInfo)
  25. Call BitBlt(Picture1.hdc, 0, 0,sBitmapInfo.bmWidth,sBitmapInfo.bmHeight,lBMDC, 0, 0, SRCCOPY)
  26. Picture1.Refresh
  27. lWidth = sBitmapInfo.bmWidth
  28. lHeight = sBitmapInfo.bmHeight
  29. lRadians = PI * Degrees / 180
  30. hRotatedBitmapDC = Picture1.hdc
  31. RotateBitmap hRotatedBitmapDC, lWidth, lHeight, lRadians
  32. Set Picture2.Picture = LoadPicture
  33. Call BitBlt(Picture2.hdc, 0, 0,             hRotatedBitmapDC, 0, 0, SRCCOPY)
  34. Picture2.Refresh
  35. Call DeleteDC(hRotatedBitmapDC)
  36. Degrees = Degrees + 90
  37. If Degrees = 360 Then
  38. Degrees = 0
  39. End If
  40. Picture1.Visible = False



In un modulo bas
Codice sorgente - presumibilmente Delphi

  1. Public Const IMAGE_BITMAP = &O0   ' used with LoadImage to load
  2.                                        ' a bitmap
  3.       Public Const LR_LOADFROMFILE = 16    ' used with LoadImage
  4.      Public Const LR_CREATEDIBSECTION = 8192 ' used with LoadImage
  5.       Public Const SRCCOPY = &HCC0020         ' (DWORD) dest = source
  6.      Public Const PI = 3.14159
  7.  
  8.      ' Refer to the MSDN for more detailed information regarding the
  9.       ' structures used in this sample.
  10.      Type BITMAP '14 bytes
  11.            bmType As Long
  12.            bmWidth As Long
  13.            bmHeight As Long
  14.            bmWidthBytes As Long
  15.            bmPlanes As Integer
  16.            bmBitsPixel As Integer
  17.            bmBits As Long
  18.       End Type
  19.  
  20.       ' Refer to the MSDN for more detailed information regarding the API's
  21.       ' used in this sample.
  22.  
  23.      Declare Function LoadImage Lib "user32" Alias "LoadImageA" _
  24.         (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, _
  25.         ByVal n1 As Long,ByVal n2 As Long, ByVal un2 As Long) As Long
  26.      Declare Function CreateCompatibleDC Lib "gdi32" _
  27.         (ByVal hdc As Long) As Long
  28.      Declare Function SelectObject Lib "gdi32" _
  29.         (ByVal hdc As Long, ByVal hObject As Long) As Long
  30.      Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, _
  31.         ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, _
  32.         ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, _
  33.         ByVal ySrc As Long, ByVal dwRop As Long) As Long
  34.      Declare Function GetObject Lib "gdi32" Alias "GetObjectA" _
  35.         (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As
  36.         Long
  37.      Declare Function CreateCompatibleBitmap Lib "gdi32" _
  38.         (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long)
  39.         As Long
  40.      Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
  41.      Declare Function DeleteObject Lib "gdi32" _
  42.         (ByVal hObject As Long) As Long
  43.  
  44.      Public Sub RotateBitmap(hBitmapDC As Long, lWidth As Long, _
  45.         lHeight As Long, lRadians As Long)
  46.  
  47.         Dim hNewBitmapDC As Long    ' DC of the new bitmap
  48.          Dim hNewBitmap As Long      ' handle to the new bitmap
  49.         Dim lSine As Long           ' sine used in rotation
  50.          Dim lCosine As Long         ' cosine used in rotation
  51.         Dim X1 As Long              ' used in calculating new
  52.                                      ' bitmap dimensions
  53.         Dim X2 As Long              ' used in calculating new
  54.                                      ' bitmap dimensions
  55.         Dim X3 As Long              ' used in calculating new
  56.                                      ' bitmap dimensions
  57.         Dim Y1 As Long              ' used in calculating new
  58.                                      ' bitmap dimensions
  59.         Dim Y2 As Long              ' used in calculating new
  60.                                      ' bitmap dimensions
  61.         Dim Y3 As Long              ' used in calculating new
  62.                                      ' bitmap dimensions
  63.         Dim lMinX As Long           ' used in calculating new
  64.                                      ' bitmap dimensions
  65.         Dim lMaxX As Long           ' used in calculating new
  66.                                      ' bitmap dimensions
  67.         Dim lMinY As Long           ' used in calculating new
  68.                                      ' bitmap dimensions
  69.         Dim lMaxY As Long           ' used in calculating new
  70.                                      ' bitmap dimensions
  71.         Dim lNewWidth As Long       ' width of new bitmap
  72.          Dim lNewHeight As Long      ' height of new bitmap
  73.         Dim I As Long               ' loop counter
  74.          Dim J As Long               ' loop counter
  75.         Dim lSourceX As Long        ' x pixel coord we are blitting
  76.                                      ' from the source  image
  77.         Dim lSourceY As Long        ' y pixel coord we are blitting
  78.                                      ' from the source image
  79.  
  80.         ' create a compatible DC from the one just brought
  81.          ' into this function
  82.         hNewBitmapDC = CreateCompatibleDC(hBitmapDC)
  83.  
  84.         ' compute the sine/cosinse of the radians used to
  85.          ' rotate this image
  86.         lSine = Sin(lRadians)
  87.         lCosine = Cos(lRadians)
  88.  
  89.         ' compute the size of the new bitmap being created
  90.          X1 = -lHeight * lSine
  91.          Y1 = lHeight * lCosine
  92.          X2 = lWidth * lCosine - lHeight * lSine
  93.          Y2 = lHeight * lCosine + lWidth * lSine
  94.          X3 = lWidth * lCosine
  95.          Y3 = lWidth * lSine
  96.  
  97.          ' figure out the max/min size of the new bitmap
  98.         lMinX = Min(0, Min(X1, Min(X2, X3)))
  99.         lMinY = Min(0, Min(Y1, Min(Y2, Y3)))
  100.         lMaxX = Max(X1, Max(X2, X3))
  101.         lMaxY = Max(Y1, Max(Y2, Y3))
  102.  
  103.         ' set the new bitmap width/height
  104.          lNewWidth = lMaxX - lMinX
  105.          lNewHeight = lMaxY - lMinY
  106.  
  107.          ' create a new bitmap based upon the new width/height of the
  108.         ' rotated bitmap
  109.          hNewBitmap = CreateCompatibleBitmap _
  110.          (hBitmapDC, lNewWidth, lNewHeight)
  111.  
  112.          ' attach the new bitmap to the new device context created
  113.         ' above before constructing the rotated bitmap
  114.          Call SelectObject(hNewBitmapDC, hNewBitmap)
  115.  
  116.          ' loop through and translate each pixel to its new location.
  117.         ' this is using a standard rotation algorithm
  118.          For I = 0 To lNewHeight
  119.             For J = 0 To lNewWidth
  120.                lSourceX = (J + lMinX) * lCosine + (I + lMinY) * lSine
  121.                lSourceY = (I + lMinY) * lCosine - (J + lMinX) * lSine
  122.                If (lSourceX >= 0) And (lSourceX <= lWidth) And _
  123.                (lSourceY >= 0) And (lSourceY <= lHeight) Then
  124.                   Call BitBlt(hNewBitmapDC, J, I, 1, 1, hBitmapDC, _
  125.                               lSourceX, lSourceY, SRCCOPY)
  126.                End If
  127.             Next J
  128.          Next I
  129.  
  130.          ' reset the new bitmap width and height
  131.         lWidth = lNewWidth
  132.         lHeight = lNewHeight
  133.  
  134.         ' return the DC to the new bitmap
  135.          hBitmapDC = hNewBitmapDC
  136.  
  137.          ' destroy the bitmap created
  138.         Call DeleteObject(hNewBitmap)
  139.  
  140.      End Sub
  141.  
  142.      Private Function Min(X1 As Long, Y1 As Long) As Long
  143.         If X1 >= Y1 Then
  144.            Min = Y1
  145.         Else
  146.            Min = X1
  147.         End If
  148.      End Function
  149.  
  150.      Private Function Max(X1 As Long, Y1 As Long) As Long
  151.         If X1 >= Y1 Then
  152.           Max = X1
  153.         Else
  154.            Max = Y1
  155.         End If
  156.      End Function


PM Quote
Pagine: [ 1 2 3 4 ] Precedente | Prossimo