Results 1 to 3 of 3

Thread: Rotate image???

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    48

    Question

    Ok, I saw many demo and project on rotate a picture. But all of them seem to be slow. Does anyone has a real fast one??

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    it's all in the processor but most are slow because of the calculations needed...Just a thought, you could use an animated gif to get the same effect.

    Look Here




    [Edited by HeSaidJoe on 09-22-2000 at 01:56 PM]
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    I don't know if you used API for the processing, but I'm sure it's quite fast (can't test it tho)

    Code:
    Const SRCCOPY = &HCC0020 
    Const Pi = 3.14159265359 
    
    Private Declare Function SetPixel Lib "GDI32" (ByVal hDC As _
    Integer, ByVal X As Integer, ByVal Y As Integer, ByVal crColor _
    As Long) As Long 
    
    Private Declare Function GetPixel Lib "GDI32" (ByVal hDC As _
    Integer, ByVal X As Integer, ByVal Y As Integer) As Long 
    
    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&) 
    
    Sub Form_Load () 
    picture1.ScaleMode = 3 
    picture2.ScaleMode = 3 
    End Sub 
    
    
    Sub Command1_Click () 
    '// Flip horizontal 
    picture2.Cls 
    px% = picture1.ScaleWidth 
    py% = picture1.ScaleHeight 
    retval% = StretchBlt(picture2.hDC, px%, 0, -px%, py%, _
    picture1.hDC, 0, 0, px%, py%, SRCCOPY) 
    End Sub 
    
    
    Sub Command2_Click () 
    '// Flip vertical 
    picture2.Cls 
    px% = picture1.ScaleWidth 
    py% = picture1.ScaleHeight 
    retval% = StretchBlt(picture2.hDC, 0, py%, px%, -py%, _
    picture1.hDC, 0, 0, px%, py%, SRCCOPY) 
    End Sub 
    
    Sub Command3_Click () 
    '// Rotate 45 degrees 
    picture2.Cls 
    Call bmp_rotate(picture1, picture2, 3.14 / 4) 
    End Sub 
    
    Sub bmp_rotate (pic1 As PictureBox, pic2 As PictureBox, ByVal theta As Long) 
    '// bmp_rotate(pic1, pic2, theta) 
    '// Rotate the image in a picture box. 
    '// Pic1 is the picture box with the bitmap to rotate 
    '// Pic2 is the picture box to receive the rotated bitmap 
    '// Theta is the angle of rotation 
    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 
    
    c1x = pic1.ScaleWidth \2 
    c1y = pic1.ScaleHeight \2 
    c2x = pic2.ScaleWidth \2 
    c2y = pic2.ScaleHeight \2 
    
    If c2x Then n="c2y" Else n="c2x" 
    n = n - 1 
    pic1hDC% = pic1.hDC 
    pic2hDC% = pic2.hDC 
    
    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(pic1hDC%, c1x + p1x, c1y + p1y) 
    c1& = GetPixel(pic1hDC%, c1x - p1x, c1y - p1y) 
    c2& = GetPixel(pic1hDC%, c1x + p1y, c1y - p1x) 
    c3& = GetPixel(pic1hDC%, c1x - p1y, c1y + p1x) 
    If c0& <> -1 Then xret& = SetPixel(pic2hDC%, c2x + p2x, c2y + p2y, c0&) 
    If c1& <> -1 Then xret& = SetPixel(pic2hDC%, c2x - p2x, c2y - p2y, c1&) 
    If c2& <> -1 Then xret& = SetPixel(pic2hDC%, c2x + p2y, c2y - p2x, c2&) 
    If c3& <> -1 Then xret& = SetPixel(pic2hDC%, c2x - p2y, c2y + p2x, c3&) 
    Next 
    t% = DoEvents() 
    Next 
    End Sub
    To Flip, rotate and mirror a picture.
    Hope it's fast!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

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