Click to See Complete Forum and Search --> : Painting a picture box
xensoft
Aug 14th, 2000, 09:14 AM
I've got a module that scans a given pixel of screen and returns it's RGB color.
Now what I want to do is to be able to change the pixel color of a given pixel on the screen.
So lets say I have 2 Picture boxes A and B. I can scan PicBoxA's RGB colors for each pixel. What I need to know is how I could replicate that same pixel in PicBox B.
Basically, I want to know how to paint a picture box's pixels different colors.
SteveCRM
Aug 14th, 2000, 09:27 AM
Im not sure how, but dennis is making a paint program and might be able to help you ;)
Try the following:
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
Private Sub Command1_Click()
'Loop through each Pixel
For X = 0 To Picture1.Width
For Y = 1 To Picture1.Height
'Get the Pixel from Picture1
crColour = GetPixel(Picture1.hdc, X, Y)
'<--Do Pixel manipulation here-->
'Draw the pixel on Picture2
SetPixel Picture2.hdc, X, Y, crColor
Next Y
Next X
End Sub
You can use SetPixel or BitBlt.
and if you want to exactly dupe the picture, you can use 2 for loops, one inside the other and use GetPixel and SetPixel to get PicA's pixel and set PicB's pixel.
here I just wrote some sample code....
you need 2 picture boxes and a command button.
and be warned this code is a little slow!
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
Private Sub Command1_Click()
Dim i As Long
Dim j As Long
Dim dPixel As Long
For i = 0 To Picture1.Width
For j = 0 To Picture1.Height
dPixel = GetPixel(Picture1.hdc, i, j)
SetPixel Picture2.hdc, i, j, dPixel
Next
Next
End Sub
Private Sub Form_Load()
Me.ScaleMode = vbPixels
Picture1.ScaleMode = vbPixels
Picture2.ScaleMode = vbPixels
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
SetPixel Picture1.hdc, X, Y, vbRed
SetPixel Picture1.hdc, X + 1, Y + 1, vbGreen
SetPixel Picture1.hdc, X + 2, Y + 2, vbYellow
End If
End Sub
it took me ten minutes to write that!!!!!
it didnt seem like that long..... time flies when your having fun :) (writing code)
Fox
Aug 14th, 2000, 11:07 AM
Indeed, hours become minutes when coding ;) (Have experience in that :))
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.