1 Attachment(s)
[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)
Re: [VB6] - the Graphics Class
"Overflow error " !!
Function RGBValues() ReturnColor.Green = (Color And 65535) / 256
should be ReturnColor.Green = (Color And 65535) \ 256
Re: [VB6] - the Graphics Class
Quote:
Originally Posted by
Tmax
"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
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)
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?
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?
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?