Skip to content

ReadPixel

Narta Xaymar Dirks edited this page Oct 28, 2026 · 7 revisions

Blitz3DBlitzPlusBlitzBasic

ReadPixel

ReadPixel:Int32 x:Int32, y:Int32, buffer:Int32=0
Parameter Mode Type Default Description
x In Int32 required Horizontal position of the pixel.
y In Int32 required Vertical position of the pixel.
buffer In Int32 0 The buffer to read from. Defaults to the current buffer.

Returns: The color of the pixel, or 0 if the position is outside of the buffer.

Description

Returns the color of a pixel of a buffer as an ARGB number: red, green and blue are in the lower three bytes, (color And $FFFFFF), and the top byte is the alpha, which is 255 for the screen. Take the parts apart with Shr and And. For many pixels, lock the buffer and use ReadPixelFast.

Differences

  • Without a lock the pixel has to be fetched from the graphics card, which makes this slow when it is used for many pixels.
  • The buffers that Graphics3D makes with a depth above 32 are read as they are stored: with the depth 30 the number is A2R10G10B10 (2 bits of alpha on top, then 10 for each of red, green and blue), and with 64 it is ARGB with 8 bits of each channel (the half floats clamped to 0 to 1), which loses the rest. ReadPixel64 gives the Float16 channels. See Color depth.

Examples

Graphics 320, 240, 0, 2
SetBuffer BackBuffer()
Cls
Color 200, 100, 50
Plot 10, 10
Local c = ReadPixel(10, 10) And $FFFFFF
Print "Red " + ((c Shr 16) And $FF) + " Green " + ((c Shr 8) And $FF) + " Blue " + (c And $FF)
WaitKey

Related Commands

CopyPixel, CopyPixelFast, ReadPixel64 〔BlitzLLVM〕, ReadPixelFast, ReadPixelFast64 〔BlitzLLVM〕, WritePixel, WritePixelFast, WritePixelFast64 〔BlitzLLVM〕

Home · Command Index



Differences
Language Features
BlitzBasic
Blitz3D
BlitzPlus

Clone this wiki locally