Results 1 to 6 of 6

Thread: Rotate an image [Resolved]

Hybrid View

  1. #1

    Thread Starter
    Lively Member UTGrim's Avatar
    Join Date
    Jan 2005
    Location
    Brazil
    Posts
    92

    Resolved Rotate an image [Resolved]

    Does anybody know how I could rotate an image by degrees, kind of like in PowerPoint, Word, or Photoshop?

    I know that I can use the PaintPicture Method to flip the image by 90, 180, or 270 degrees.

    Thanks!
    Last edited by UTGrim; Mar 20th, 2005 at 01:47 PM.

  2. #2
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Rotate an image

    This should help ya do it in real time using DirectX8. However, if ya want to learn how to do it using regular API's, these other people might help you with that, but it's slow and still a bit advanced.
    Attached Files Attached Files

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Rotate an image


  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Rotate an image

    Something like this could work too (API, no DX):


    VB Code:
    1. Const SRCCOPY = &HCC0020
    2. Const Pi = 3.14159265359
    3. Private Declare Function SetPixel Lib "GDI32" (ByVal hDC As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal crColor As Long) As Long
    4. Private Declare Function GetPixel Lib "GDI32" (ByVal hDC As Integer, ByVal X As Integer, ByVal Y As Integer) As Long
    5. 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&)
    6.  
    7. '  add three command buttons and two pictureboxes. Load a bitmap into picture1 in design
    8. '  mode. Set both box to the same size. Routines execute 3 times faster than routines
    9. '  found in Microsoft's Knowledge Base.
    10.  
    11.  
    12. 'Sub Form_Load ()
    13. Picture1.ScaleMode = 3
    14. Picture2.ScaleMode = 3
    15. 'End Sub
    16.  
    17. 'Sub Command1_Click ()
    18. 'flip horizontal
    19. picture2.Cls
    20. px% = picture1.ScaleWidth
    21. py% = picture1.ScaleHeight
    22. retval% = StretchBlt(picture2.hDC, px%, 0, -px%, py%, picture1.hDC, 0, 0, px%, py%, SRCCOPY)
    23. 'End Su
    24.  
    25. 'Sub Command2_Click ()
    26.                 'flip vertical
    27.                 picture2.Cls
    28.                 px% = picture1.ScaleWidth
    29.                 py% = picture1.ScaleHeight
    30.                 retval% = StretchBlt(picture2.hDC, 0, py%, px%, -py%, picture1.hDC, 0, 0, px%, py%, SRCCOPY)
    31.                'End Sub
    32.  
    33.                'Sub Command3_Click ()
    34.                 'rotate 45 degrees
    35.                 picture2.Cls
    36.                 Call bmp_rotate(picture1, picture2, 3.14 / 4)
    37.                'End Sub
    38.  
    39.  
    40. 'Sub bmp_rotate (pic1 As PictureBox, pic2 As PictureBox, ByVal theta!)
    41.   ' bmp_rotate(pic1, pic2, theta)
    42.   ' Rotate the image in a picture box.
    43.   '   pic1 is the picture box with the bitmap to rotate
    44.   '   pic2 is the picture box to receive the rotated bitmap
    45.   '   theta is the angle of rotation
    46.   Dim c1x As Integer, c1y As Integer
    47.   Dim c2x As Integer, c2y As Integer
    48.   Dim a As Single
    49.   Dim p1x As Integer, p1y As Integer
    50.   Dim p2x As Integer, p2y As Integer
    51.   Dim n As Integer, r   As Integer
    52.  
    53.   c1x = pic1.ScaleWidth \ 2
    54.   c1y = pic1.ScaleHeight \ 2
    55.   c2x = pic2.ScaleWidth \ 2
    56.   c2y = pic2.ScaleHeight \ 2
    57.   If c2x < c2y Then n = c2y Else n = c2x
    58.   n = n - 1
    59.   pic1hDC% = pic1.hDC
    60.   pic2hDC% = pic2.hDC
    61.  
    62.         For p2x = 0 To n
    63.             For p2y = 0 To n
    64.           If p2x = 0 Then a = Pi / 2 Else a = Atn(p2y / p2x)
    65.           r = Sqr(1& * p2x * p2x + 1& * p2y * p2y)
    66.         p1x = r * Cos(a + theta!)
    67.         p1y = r * Sin(a + theta!)
    68.         c0& = GetPixel(pic1hDC%, c1x + p1x, c1y + p1y)
    69.         c1& = GetPixel(pic1hDC%, c1x - p1x, c1y - p1y)
    70.         c2& = GetPixel(pic1hDC%, c1x + p1y, c1y - p1x)
    71.         c3& = GetPixel(pic1hDC%, c1x - p1y, c1y + p1x)
    72.         If c0& <> -1 Then xret& = SetPixel(pic2hDC%, c2x + p2x, c2y + p2y, c0&)
    73.         If c1& <> -1 Then xret& = SetPixel(pic2hDC%, c2x - p2x, c2y - p2y, c1&)
    74.         If c2& <> -1 Then xret& = SetPixel(pic2hDC%, c2x + p2y, c2y - p2x, c2&)
    75.         If c3& <> -1 Then xret& = SetPixel(pic2hDC%, c2x - p2y, c2y + p2x, c3&)
    76.       Next
    77.     t% = DoEvents()
    78.    Next
    79. 'End Sub

  5. #5

    Thread Starter
    Lively Member UTGrim's Avatar
    Join Date
    Jan 2005
    Location
    Brazil
    Posts
    92

    Re: Rotate an image

    Quote Originally Posted by NoteMe
    Something like this could work too (API, no DX):
    Cool! I can do some nice effects with this one.

  6. #6
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Rotate an image [Resolved]

    No problem, just happy to help out.



    ØØ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width