Results 1 to 3 of 3

Thread: [RESOLVED]Rotating image

  1. #1

    Thread Starter
    Hyperactive Member Private_sub's Avatar
    Join Date
    Nov 2005
    Location
    +31
    Posts
    368

    Resolved [RESOLVED]Rotating image

    How can you rotate an image for like 90 degrees?

    Thanx
    Last edited by Private_sub; Jan 8th, 2006 at 05:46 AM.

  2. #2
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Totating image

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

  3. #3

    Thread Starter
    Hyperactive Member Private_sub's Avatar
    Join Date
    Nov 2005
    Location
    +31
    Posts
    368

    Re: Totating image

    Thanks! It works

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