Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Picking Colors from the Screen

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBWin/PBCC Picking Colors from the Screen

    There is an easy way to pick and identify the colors in the screen of a running application, using one of the new features of PB’s Graphic Window. As everybody knows, pressing the Print Screen key puts a bitmap of the whole screen into the clipboard. Compiling and running the code below you can put that Bitmap into your Graphic Window, and for every mouse click you can get the color of the target pixel.
    Code:
    [FONT=Calibri][SIZE=3][/SIZE][/FONT] 
    [FONT=Calibri][SIZE=3]#COMPILE EXE[/SIZE][/FONT]
    [FONT=Calibri][SIZE=3]#CONSOLE OFF    'comment to compile in PB9[/SIZE][/FONT]
    [FONT=Calibri][SIZE=3]DEFLNG a-z[/SIZE][/FONT]
    [FONT=Calibri][SIZE=3] [/SIZE][/FONT]
    [FONT=Calibri][SIZE=3]GLOBAL  O$, clk&, xm!, ym![/SIZE][/FONT]
    [FONT=Calibri][SIZE=3]GLOBAL  hwin, hven, PL  AS LONG[/SIZE][/FONT]
    [FONT=Calibri][SIZE=3] [/SIZE][/FONT]
    [FONT=Calibri][SIZE=3]FUNCTION PBMAIN () AS LONG[/SIZE][/FONT]
    [SIZE=3][FONT=Calibri] DESKTOP GET CLIENT TO PixW,PixH[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri] x1=0[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri] y1=0[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri] x2=PixW[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri] y2=PixH[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri] GRAPHIC WINDOW caption$, x1, y1, x2, y2  TO  hwin[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri] GRAPHIC ATTACH hwin, 0, REDRAW[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri] GRAPHIC SET LOC -3, 0[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri] CLIPBOARD GET BITMAP hven[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri] GRAPHIC COPY hven, 0[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri] GRAPHIC REDRAW[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri] FONT NEW "Courier New",10,0,0,0,0 TO fnt1[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri] GRAPHIC SET FONT fnt1[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri] DO[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]  GRAPHIC INKEY$ TO O$[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]  GRAPHIC WINDOW CLICK TO clk&, xm!, ym![/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]  IF clk& THEN[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]   GRAPHIC GET PIXEL(xm!, ym!)TO PL[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]   HC$=RIGHT$(STRING$(6,48)+HEX$(PL),6)[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]   BC%=16*VAL("&H"+MID$(HC$,1,1))+VAL("&H"+MID$(HC$,2,1))[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]   GC%=16*VAL("&H"+MID$(HC$,3,1))+VAL("&H"+MID$(HC$,4,1))[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]   RC%=16*VAL("&H"+MID$(HC$,5,1))+VAL("&H"+MID$(HC$,6,1))[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]   WAV%=(2*BC%+3*GC%+RC%)/6[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]   IF WAV%<138 THEN[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]    GRAPHIC COLOR %WHITE,PL[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]   ELSE[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]    GRAPHIC COLOR %BLACK,PL[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]   END IF[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]   IF xm!>x2-128 THEN xm!=x2-128[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]   IF ym!>y2-50 THEN ym!=y2-50[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]   GRAPHIC SET POS(xm!,ym!)[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]   GRAPHIC PRINT "DEC: "+USING$("########",PL)+STRING$(3,32)[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]   GRAPHIC SET POS(xm!,ym!+16)[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]   GRAPHIC PRINT "HEX: &H"+HC$+STRING$(3,32)[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]   GRAPHIC SET POS(xm!,ym!+32)[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]   GRAPHIC PRINT "RGB("+USING$("###",RC%)+CHR$(44)+USING$("###",GC%)+CHR$(44)+USING$("###",BC%)+")"[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]  END IF[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]  IF O$ = CHR$(27) THEN EXIT LOOP[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri]  GRAPHIC REDRAW[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri] LOOP[/FONT][/SIZE]
    [SIZE=3][FONT=Calibri] GRAPHIC WINDOW END[/FONT][/SIZE]
    [FONT=Calibri][SIZE=3]END FUNCTION[/SIZE][/FONT]
Working...
X