1 Attachment(s)
[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?
1 Attachment(s)
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:
Vertex(0).X = Center.X - Half_Img_Size.X: Vertex(0).Y = Center.Y - Half_Img_Size.Y
Vertex(1).X = Center.X + Half_Img_Size.X: Vertex(1).Y = Center.Y - Half_Img_Size.Y
Vertex(2).X = Center.X - Half_Img_Size.X: Vertex(2).Y = Center.Y + Half_Img_Size.Y
Vertex(3).X = Center.X + Half_Img_Size.X: Vertex(3).Y = Center.Y + Half_Img_Size.Y
New_Vertex(0).X = X + (Vertex(0).X * Cos(Angle * (PI / 180)) - Vertex(0).Y * Sin(Angle * (PI / 180)))
New_Vertex(0).Y = Y + (Vertex(0).X * Sin(Angle * (PI / 180)) + Vertex(0).Y * Cos(Angle * (PI / 180)))
New_Vertex(1).X = X + (Vertex(1).X * Cos(Angle * (PI / 180)) - Vertex(1).Y * Sin(Angle * (PI / 180)))
New_Vertex(1).Y = Y + (Vertex(1).X * Sin(Angle * (PI / 180)) + Vertex(1).Y * Cos(Angle * (PI / 180)))
New_Vertex(2).X = X + (Vertex(2).X * Cos(Angle * (PI / 180)) - Vertex(2).Y * Sin(Angle * (PI / 180)))
New_Vertex(2).Y = Y + (Vertex(2).X * Sin(Angle * (PI / 180)) + Vertex(2).Y * Cos(Angle * (PI / 180)))
New_Vertex(3).X = X + (Vertex(3).X * Cos(Angle * (PI / 180)) - Vertex(3).Y * Sin(Angle * (PI / 180)))
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:
Re: [VB6] - the Graphics Class
joaquim
The procedure DrawImageData, when you call StretchDIBits bmi structure contains options of ImageData array, but must ImageDataChanged.
Re: [VB6] - the Graphics Class
Quote:
Originally Posted by
Mikle
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?:()
1 Attachment(s)
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
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?
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)