Results 1 to 7 of 7

Thread: [VB6] - the Graphics Class

  1. #1
    PowerPoster joaquim's Avatar
    Join Date
    Apr 07
    Posts
    2,494

    [VB6] - the Graphics Class

    heres my class on attachments files...
    heres how use it:
    Code:
    Set ImageData = New Graphics
        ImageData.GetImageData Picture2
        ImageData.BackColor = vbYellow
        ImageData.Rotate = 45
        ImageData.Mirror = HorizontalVertical
        
        ImageData.DrawImageData Picture1, 40, 40
        Set ImageData = Nothing
    i have 2 errors:
    1 - the BackColor isn't changed and i don't see why
    Code:
    'change image backcolor
                If ImageDataChanged(X + 2, Y) <> clrBackColor.Red And ImageDataChanged(X + 1, Y) <> clrBackColor.Green And ImageDataChanged(X, Y) <> clrBackColor.Blue Then
                    ImageDataChanged(X + 2, Y) = clrBackColor.Red
                    ImageDataChanged(X + 1, Y) = clrBackColor.Green
                    ImageDataChanged(X, Y) = clrBackColor.Blue
                End If
    2 - by some reason the rotation values\results aren't corrected
    Code:
    For X = 0 To ByteAlignOnWord(bmi.bmHeader.bmBitCount, lngWidthImage) - 3 Step 3
            For Y = 0 To lngHeigthImage - 1
                'Rotate an image
                If lngRotate <> 0 Then
                    RC = InvRotateCoord(X, Y, lngWidthImage / 2, lngHeigthImage / 2, lngRotate)
                    If RC.RotatedX <= 0 Or RC.RotatedX >= bm.bmWidth Or RC.RotatedY <= 0 Or RC.RotatedY >= bm.bmHeight Then
                        'do nothing
                    Else
                        ImageDataChanged(X + 2, Y) = ImageData(RC.RotatedX + 2, RC.RotatedY)
                        ImageDataChanged(X + 1, Y) = ImageData(RC.RotatedX + 1, RC.RotatedY)
                        ImageDataChanged(X, Y) = ImageData(RC.RotatedX, RC.RotatedY)
                        If RGB(ImageDataChanged(X + 2, Y), ImageDataChanged(X + 1, Y), ImageDataChanged(X, Y)) = &HFFFF Or X >= bm.bmWidth Or Y >= bm.bmHeight Then
                            ImageDataChanged(X + 2, Y) = clrOldBackColor.Red
                            ImageDataChanged(X + 1, Y) = clrOldBackColor.Green
                            ImageDataChanged(X, Y) = clrOldBackColor.Blue
                        End If
                    End If
                Else
                    ImageDataChanged(X + 2, Y) = ImageData(X + 2, Y)
                    ImageDataChanged(X + 1, Y) = ImageData(X + 1, Y)
                    ImageDataChanged(X, Y) = ImageData(X, Y)
                End If
    ca anyone advice me?
    Attached Files Attached Files
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    The DirectXpert Jacob Roman's Avatar
    Join Date
    Aug 04
    Location
    Miami Beach, FL
    Posts
    4,832

    Re: [VB6] - the Graphics Class

    Without having to download it, the backcolor doesnt change cause all 3 cases must pass in your If statement. So lets say the backcolor is black which is 0 0 0. Lets just let X and Y be just one pixel, at (0, 0). If ImageDataChanged(0 + 2, 0) is not equal to clrBackColor.Red And so on and so forth for Green and Blue, it won't change.

    Also for rotation, be sure you are using radians and not degrees, and also be sure you are doing it from the center of the image when something like this:

    vb Code:
    1. Vertex(0).X = Center.X - Half_Img_Size.X: Vertex(0).Y = Center.Y - Half_Img_Size.Y
    2.     Vertex(1).X = Center.X + Half_Img_Size.X: Vertex(1).Y = Center.Y - Half_Img_Size.Y
    3.     Vertex(2).X = Center.X - Half_Img_Size.X: Vertex(2).Y = Center.Y + Half_Img_Size.Y
    4.     Vertex(3).X = Center.X + Half_Img_Size.X: Vertex(3).Y = Center.Y + Half_Img_Size.Y
    5.    
    6.     New_Vertex(0).X = X + (Vertex(0).X * Cos(Angle * (PI / 180)) - Vertex(0).Y * Sin(Angle * (PI / 180)))
    7.     New_Vertex(0).Y = Y + (Vertex(0).X * Sin(Angle * (PI / 180)) + Vertex(0).Y * Cos(Angle * (PI / 180)))
    8.    
    9.     New_Vertex(1).X = X + (Vertex(1).X * Cos(Angle * (PI / 180)) - Vertex(1).Y * Sin(Angle * (PI / 180)))
    10.     New_Vertex(1).Y = Y + (Vertex(1).X * Sin(Angle * (PI / 180)) + Vertex(1).Y * Cos(Angle * (PI / 180)))
    11.    
    12.     New_Vertex(2).X = X + (Vertex(2).X * Cos(Angle * (PI / 180)) - Vertex(2).Y * Sin(Angle * (PI / 180)))
    13.     New_Vertex(2).Y = Y + (Vertex(2).X * Sin(Angle * (PI / 180)) + Vertex(2).Y * Cos(Angle * (PI / 180)))
    14.    
    15.     New_Vertex(3).X = X + (Vertex(3).X * Cos(Angle * (PI / 180)) - Vertex(3).Y * Sin(Angle * (PI / 180)))
    16.     New_Vertex(3).Y = Y + (Vertex(3).X * Sin(Angle * (PI / 180)) + Vertex(3).Y * Cos(Angle * (PI / 180)))

    Well in this case I'm doing it as vertices. But I do have some old code to literally "Perspective Correct Texture Map" an image regardless of angle correctly, or you'll end up with cracks and holes. This scanlines the image from top to bottom. Unfortunately its in 3D in pure VB, but if you remove the Z's it'll still work in 2D for 2D rotation:
    Attached Files Attached Files
    Useful Forum Tips:

    - If you found any post that was useful, please consider rating their post

    - Give sensible thread titles, please!
    - Be sure to use [HIGHLIGHT=VB][/HIGHLIGHT] tags when posting code written in VB.
    - Write posts like a conversation, not like an email. That way you can avoid saying "Dear so and so" in every post.
    - When your problem is solved, go up to Thread Tools and click on Mark Thread Resolved

    My Contributions: Massive DirectX 2D Tutorials For VB5/VB6/VB.NET || 3D Engine In Pure VB || Friction Force ||DJ Turntable Simulation || Scratching Wavs || Time Based Movement || Newton Physics Simulation || Managed Game Loop || Rigid Body Collision Detection || World of Warcraft RGB Battle System || Bosskillers (World of Warcraft 2D Clone) || Street Fighter Controls (Flawless Simulation) || A* Pathfinding (VB6 & VB.NET) *UPDATED || *NEW* Nintendo Entertainment System Emulator

    Expert. Ask me anything NES!

    My Smilies:


  3. #3
    Lively Member Mikle's Avatar
    Join Date
    Oct 09
    Location
    Tuapse, Russia
    Posts
    76

    Re: [VB6] - the Graphics Class

    joaquim
    The procedure DrawImageData, when you call StretchDIBits bmi structure contains options of ImageData array, but must ImageDataChanged.

  4. #4
    PowerPoster joaquim's Avatar
    Join Date
    Apr 07
    Posts
    2,494

    Re: [VB6] - the Graphics Class

    Quote Originally Posted by Mikle View Post
    joaquim
    The procedure DrawImageData, when you call StretchDIBits bmi structure contains options of ImageData array, but must ImageDataChanged.
    thanks. i found that error and more. that's why some properties results wasn't corrects lol.
    thanks for the help my friend.
    but what you can tell me about the rotation effect?
    (if the rotate property is 0(zero), the image is showed normaly. and the other effects works normaly too. but what isn't right with our rotate effect?)
    VB6 2D Sprite control

    To live is difficult, but we do it.

  5. #5
    PowerPoster joaquim's Avatar
    Join Date
    Apr 07
    Posts
    2,494

    Re: [VB6] - the Graphics Class

    heres the class updated... but with rotate problem
    only, when, rotate diferent 0(zero), the bad results are showed. if the rotate is 0(zero), the image is showed normaly
    Attached Files Attached Files
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6
    PowerPoster joaquim's Avatar
    Join Date
    Apr 07
    Posts
    2,494

    Re: [VB6] - the Graphics Class

    i think i know where is the error:
    Code:
    If lngRotate <> 0 Then
                    RC = InvRotateCoord(X, Y, lngWidthImage / (3 * bmi.bmHeader.bmBitCount) / 2, lngHeigthImage / 2, lngRotate)
                    If RC.RotatedX < 0 Or RC.RotatedX >= bm.bmWidth Or RC.RotatedY < 0 Or RC.RotatedY >= bm.bmHeight Then
                        'do nothing
                    Else
                        ImageDataChanged(X + 2, Y) = ImageData(RC.RotatedX / (3 * bmi.bmHeader.bmBitCount) + 2, RC.RotatedY)
                        ImageDataChanged(X + 1, Y) = ImageData(RC.RotatedX / (3 * bmi.bmHeader.bmBitCount) + 1, RC.RotatedY)
                        ImageDataChanged(X, Y) = ImageData(RC.RotatedX / (3 * bmi.bmHeader.bmBitCount), RC.RotatedY)
                    End If
    Code:
    Private Function ByteAlignOnWord(ByVal bitDepth As Byte, ByVal Width As Long) As Long
        ' function to align any bit depth on dWord boundaries
        ByteAlignOnWord = (((Width * bitDepth) + &H1F&) And Not &H1F&) \ &H8&
    End Function
    because i know that x limite isByteAlignOnWord(bmi.bmHeader.bmBitCount, lngWidthImage), i must found X0(center of X) and then convert it, i belive. that's why i have the bad results. any advices for fix these problem?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  7. #7
    PowerPoster joaquim's Avatar
    Join Date
    Apr 07
    Posts
    2,494

    Re: [VB6] - the Graphics Class

    for test: can anyone explain to me how can i use normal X,Y positions... without RGB way?
    (normal 2D array)
    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
  •