Results 1 to 7 of 7

Thread: [VB6] - the Graphics Class

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

    [VB6] - the Graphics Class

    hehehe
    only vb2010 have these class!?! naaaaaaaaaaaaaa.
    now i'm building a nice class that i want to share.
    for now these class do:
    1 - catch the image from any(i belive) device\control that have hdc property(but 100% sure on forms, pictureboxes and usercontrols);
    2 - have nice effects:
    - BackColor;
    - Transparent(you can choose the transparent color);
    - Mirror;
    - BlackAndWhite;
    - changing colors;
    - in time i will put the Rotation and more nice effects. accept advices;
    3 - you can draw it in any(i belive) device\control that have hdc property(but 100% sure on forms, pictureboxes and usercontrols). you can draw it on any position you like
    (the image size, i belive, is showed in pixels)
    and heres how use it:
    Code:
    Dim ImageData As Graphics
    
    Private Sub Command1_Click()
        Set ImageData = New Graphics
        ImageData.GetImageData Picture2
        ImageData.BackColor = vbBlue
        ImageData.Transparent = True
        ImageData.Mirror = HorizontalVertical
        ImageData.BlackAndWhite = True
        ImageData.DrawImageData Picture1, 40, 40 'the 40 and 40 is for tell the position;)
        Set ImageData = Nothing
    End Sub
    now the vb6 gamer programmers don't need use advanced stuff or API functions. because these class helps very much
    (class updated: 18/06/2012)
    Attached Files Attached Files
    Last edited by joaquim; Oct 5th, 2012 at 11:03 AM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    New Member Tmax's Avatar
    Join Date
    Nov 10
    Posts
    13

    Re: [VB6] - the Graphics Class

    "Overflow error " !!
    Function RGBValues() ReturnColor.Green = (Color And 65535) / 256
    should be ReturnColor.Green = (Color And 65535) \ 256

  3. #3
    PowerPoster joaquim's Avatar
    Join Date
    Apr 07
    Posts
    2,497

    Re: [VB6] - the Graphics Class

    Quote Originally Posted by Tmax View Post
    "Overflow error " !!
    Function RGBValues() ReturnColor.Green = (Color And 65535) / 256
    should be ReturnColor.Green = (Color And 65535) \ 256
    you correct me more than that.
    THANKS
    VB6 2D Sprite control

    To live is difficult, but we do it.

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

    Re: [VB6] - the Graphics Class

    now i'm working with shadow effect... but the code don't work... give me an ranger index error
    i have the image in ChangeImage() array with outWidth and outHeight limits. know i just compare the pixels colors for give the image shadow in same array. but the code gives me the index error
    Code:
    'Shadow Effect
                If lngShadowX <> 0 Or lngShadowY <> 0 Then
                    'convert backcolor to RGB values
                    clrOldColor = RGBValues(lngBackColor)
                        'test if the color is a backcolor
                        If ChangedImage(X, Y) <> RGB(clrOldColor.Blue, clrOldColor.Green, clrOldColor.Red) Then
                        
                            'for avoid the range index error
                            If X + lngShadowX <= outWidth Or Y + lngShadowY <= outHeight Then
                           'test if the shadow position have a backcolor
                            If ChangedImage(X + lngShadowX, Y + lngShadowY) = RGB(clrOldColor.Blue, clrOldColor.Green, clrOldColor.Red) Then
                                clrOldColor = RGBValues(lngShadowColor)
                                'if so then change it to shadow color
                                ChangedImage(X + lngShadowX, Y + lngShadowY) = RGB(clrOldColor.Blue, clrOldColor.Green, clrOldColor.Red)
                                'Debug.Print "hi"
                            End If
                            End If
                        End If
                End If
    can anyone advice me?
    (if my explication\code is confused, please tell me)
    VB6 2D Sprite control

    To live is difficult, but we do it.

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

    Re: [VB6] - the Graphics Class

    i correct the range index error... instead 'or' i must use 'and':
    Code:
    'Shadow Effect
                clrOldColor = RGBValues(lngBackColor)
                If ((lngShadowX <> 0) Or (lngShadowY <> 0)) And (lngShadowColor <> lngBackColor) Then
                    If (ChangedImage(X, Y) <> RGB(clrOldColor.Blue, clrOldColor.Green, clrOldColor.Red)) Then
                            If X + lngShadowX <= outWidth - 1 And Y + ShadowY <= outHeight - 1 Then
                              
                            If (ChangedImage(X + lngShadowX, Y + lngShadowY) = RGB(clrOldColor.Blue, clrOldColor.Green, clrOldColor.Red)) Then
                                Debug.Print "hi"
                                clrOldColor = RGBValues(lngShadowColor)
                                ChangedImage(X + lngShadowX, Y + lngShadowY) = vbRed
                                'Debug.Print RGB(clrOldColor.Blue, clrOldColor.Green, clrOldColor.Red)
                                
                            End If
                            End If
                        
                    End If
    but by some reason don't enter on these 'if':
    Code:
    If (ChangedImage(X + lngShadowX, Y + lngShadowY) = RGB(clrOldColor.Blue, clrOldColor.Green, clrOldColor.Red)) Then
                                Debug.Print "hi"
                                clrOldColor = RGBValues(lngShadowColor)
                                ChangedImage(X + lngShadowX, Y + lngShadowY) = vbRed
                                'Debug.Print RGB(clrOldColor.Blue, clrOldColor.Green, clrOldColor.Red)
                                
                            End If
    these 'if' test if ChangedImage(X + lngShadowX, Y + lngShadowY) pixel position have these backcolor(RGB(clrOldColor.Blue, clrOldColor.Green, clrOldColor.Red)). on image test, i know that have it, but it's ignored and i don't understand why
    can anyone advice me?
    VB6 2D Sprite control

    To live is difficult, but we do it.

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

    Re: [VB6] - the Graphics Class

    after some work and test, the shadow only works with negative positions(on left side):
    Code:
    'Shadow Effect
                If ((lngShadowX <> 0) Or (lngShadowY <> 0)) And (lngShadowColor <> lngBackColor) Then
                    'Covert the backcolor from RGB to BGR
                    clrOldColor = RGBValues(lngBackColor)
                    TempColor = RGB(clrOldColor.Blue, clrOldColor.Green, clrOldColor.Red)
                    'test if the index have the backcolor
                    'if not do something
                    If (ChangedImage(X, Y) <> TempColor) Then
                        'avoiding the range index error
                        If X + lngShadowX <= outWidth - 1 And Y + ShadowY <= outHeight - 1 Then
                            'test if the index have the backcolor
                            'if yes then do something
                            If (ChangedImage(X + lngShadowX, Y + lngShadowY) = TempColor) Then
                                'convert lngShadowColor from RGB to BGR
                                
                                clrOldColor = RGBValues(lngShadowColor)
                                TempColor = RGB(clrOldColor.Blue, clrOldColor.Green, clrOldColor.Red)
                                'change the pixel to shadow color
                                ChangedImage(X + lngShadowX, Y + lngShadowY) = TempColor
                                Debug.Print ChangedImage(X + lngShadowX, Y + lngShadowY), ChangedImage(X + lngShadowX, Y + lngShadowY)
                            End If
                        End If
                    End If
                End If
    but i don't understand why i can't use positive positions
    any advices?
    VB6 2D Sprite control

    To live is difficult, but we do it.

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

    Re: [VB6] - the Graphics Class

    finally i isolate the problem to minium
    Code:
    '.................
    for Y = 0 To outHeight - 1
    '................................
    If lngShadowY <= 0 Then
                        'error
                        TempY = outHeight - 1 - (Y + lngShadowY)
                        TempX = X + lngShadowX
                    Else
                        TempY = Y - lngShadowY
                        TempX = X + lngShadowX
                        'Debug.Print TempX; TempY
                    End If
    i know that DIB's Y work upside down. can anyone advice me on convert Y coordenate?
    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
  •