-
Picture Box
Is there a way to retrieve each pixel color (RGB) in a picture box?
Cause I want to select some pixels (with the mouse) from a picture loaded in a picture box and then retrieve each selected pixel colors to modify it and affect theses pixels to another picture box. Any Idea how to do?
-
Private Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function SetPixel Lib "gdi32" Alias "SetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
Make sure your Pic's ScaleMode is set to Pixel, then...
For x = 0 to pic.ScaleWidth - 1
For y = 0 to pic.ScaleHeight - 1
lColor = GetPixel(pic.hdc,x,y)
Setcolor(pic.hdc,x,y,lColor)
Next y
Next x
This code would just set the pixels to the same color they already were, so it's useless, but you get the idea.
-
!!!!
Thanks a lot! It Should do quite well the job!
-
Hey Megistral, if you're interested in a faster method, I can post it here ;)
Btw, SetPixelV is faster than SetPixel...
-
Thks...
Thanks Jotaf98 but I've found a new way to Stretch my picture and to set pixel
To stretch I've used PaintPicture that comes with with the Picture Box (cause I don't need to stretch very often so it's ok) and for setting pixels, I will use BitBlt.
Is the speed the only difference Between Setpixel and SetpixelV ?
-
The reason it is speedier is because SetPixelV doesn't return anything.