Blitz3D+ Command Reference

GetColor x,y

Parameters

x - x coordinate of the pixel to sample

y - y coordinate of the pixel to sample

Description

Sets the drawing colour to the colour of a pixel on the current buffer.

It works like the eyedropper in a paint program: point it at a pixel and the drawing colour becomes that pixel's colour. It is a statement, not a function - it returns nothing. To find out what colour it picked up, read ColorRed(), ColorGreen() and ColorBlue() afterwards.

Good for paint tools and for matching drawing to artwork - sample a pixel of a loaded background and draw UI in the same shade. If you want the colour as a single value instead (and no change to the drawing colour), use ReadPixel.

The pixel is read from the current buffer, so make sure the thing you are sampling has been drawn there - on the usual back-buffer setup that means after you draw it, before Flip.

See also: Color, ColorRed, ColorGreen, ColorBlue, ReadPixel.

Example

; GetColor Example
; ----------------

Graphics 640,480,0,2
SetBuffer BackBuffer()

; A colourful photo to pick colours from
logo=LoadImage("media/b3dlogo.jpg")

While Not KeyDown(1)

    Cls
    DrawImage logo,120,140

    ; GetColor grabs the colour of the pixel under the mouse...
    GetColor MouseX(),MouseY()

    ; ...and ColorRed/Green/Blue read the picked colour back
    r=ColorRed()
    g=ColorGreen()
    b=ColorBlue()

    ; Show the picked colour as a swatch next to the pointer
    Color r,g,b
    Rect MouseX()+12,MouseY()+12,24,24,1
    Color 255,255,255
    Rect MouseX()+11,MouseY()+11,26,26,0

    Text 0,0,"Move the mouse over the photo to pick colours   Esc: exit"
    Text 0,20,"GetColor "+MouseX()+","+MouseY()+"  ->  RGB "+r+","+g+","+b

    Flip

Wend

End

Index