Results 1 to 13 of 13

Thread: [RESOLVED] my own prcedure for rotate an image

Threaded View

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,959

    Resolved [RESOLVED] my own prcedure for rotate an image

    i'm using visual basic 6...
    i build these procedure:

    Code:
    Option Explicit
    
    Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
    Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
    
    Public Sub RotateImage(PicDestiny As PictureBox, PicSource As PictureBox, Angle As Long, Optional PosX As Long = 0, Optional PosY As Long = 0)
        Dim X1 As Long
        Dim Y1 As Long
        Dim X2 As Long
        Dim Y2 As Long
        Dim X As Long
        Dim Y As Long
        Dim result As Long
        Const PI = 3.14
        'Clear the picture destiny
        PicDestiny.Cls
        Angle = Angle * (PI / 180)
        For X1 = 0 To PicSource.Width
            For Y1 = 0 To PicSource.Height
                result = GetPixel(PicSource.hdc, X1, Y1)
                If result <> -1 Then
                    'Calculate the position in a circule by using the center X, Y
                    X = X1 - (PicSource.Width / 2)
                    Y = Y1 - (PicSource.Height / 2)
                    'Calculate the new position
                    X2 = (X * Cos(Angle) - Y * Sin(Angle)) + (PicSource.Height / 2)
                    Y2 = (X * Sin(Angle) + Y * Cos(Angle)) + (PicSource.Width / 2)
                    'After changed, put the pixel in new position in picDestiny
                    SetPixel PicDestiny.hdc, X2, Y2, GetPixel(PicSource.hdc, X1, Y1)
                End If
            Next Y1
        Next X1
    End Sub
    i don't know what isn't right with these procedure...
    you can see the error in an output picturebox, in bottom image...
    i don't know why i can see transparent pixels...
    can anyone help me fix these bug?
    thanks
    Attached Images Attached Images  
    VB6 2D Sprite control

    To live is difficult, but we do it.

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