|
Post by bluatigro on Nov 12, 2018 4:05:17 GMT -5
i looked but i can not find this : how do i read a color from a pixel ans what does this return ?
i only fond this :
COLORREF GetPixel( HDC hdc, int x, int y );
|
|
|
Post by tenochtitlanuk on Nov 12, 2018 4:46:31 GMT -5
No native way. Since the structure of a 24bit bmp file is known, you can 'getbmp' of the chosen pixel and read the three colours. This works and is usable in JB too. In LB we can read by using Windows functions. Example below reads all the pixels of a screen and replaces them with their RGB colours rotated. I've used this a lot ( see my many web examples) but it is NOT fast!
nomainwin
WindowWidth =500 WindowHeight =500
open "getpixel in Liberty BASIC" for graphics_nsb as #wg
#wg "trapclose quit"
handleg =hwnd( #wg) calldll #user32, "GetDC", handleg as ulong, hDC as ulong
#wg "down ; fill 110 110 60 ; color 110 110 60" #wg "backcolor 255 0 0 ; goto 150 150 ; circlefilled 100" #wg "backcolor 0 255 0 ; goto 300 250 ; circlefilled 100" #wg "backcolor 0 0 255 ; goto 150 350 ; circlefilled 100"
for x =1 to 500 for y =1 to 500
calldll #gdi32, "GetPixel", hDC as ulong, x as long, y as long, pixcol as ulong bl = int( pixcol /( 256*256)) gr = int( (pixcol -bl *256*256) / 256) re = int( pixcol -bl *256*256 -gr *256) grey = int( ( bl +gr +re) /3 /32) ' not eye-sensitivity adjusted #wg "color "; gr; " "; bl; " "; re #wg "set "; x; " "; y
scan next y next x
wait
sub quit h$ close #h$ callDll #user32, "ReleaseDC", handleg as ulong, hDC as ulong, result as ushort end end sub
|
|
|
Post by tenochtitlanuk on Nov 12, 2018 9:48:32 GMT -5
|
|
|
Post by Alyce Watson on Nov 12, 2018 10:26:08 GMT -5
i looked but i can not find this : how do i read a color from a pixel ans what does this return ? i only fond this : COLORREF GetPixel( HDC hdc, int x, int y );
It returns a long value, from which you can extract the RGB. Here's a snippet to extract the red, green and blue color values from a long value. Get RGBThe following set of tutorials explain the HDC (handle to the device context) and how to use it. API Graphics Tutorials
|
|