WritePixel x,y,argb[,buffer]

Parameters

x - x coordinate of the pixel

y - y coordinate of the pixel

argb - colour to write, as one integer: alpha, red, green and blue bytes

buffer (optional) - buffer to write to, e.g. BackBuffer(); the current buffer set with SetBuffer (default)

Description

Writes a pixel colour, given as an ARGB integer.

The colour packs all four channels into one integer - build it with shifts: argb = (alpha Shl 24) Or (red Shl 16) Or (green Shl 8) Or blue. Alpha matters when writing into image or texture buffers with alpha; for plain screen drawing use $FF for alpha. Unlike Plot, which uses the current Color, WritePixel takes the exact value - which makes it the natural partner of ReadPixel for copying and tweaking pixels.

Writes respect the current Origin and are clipped to the Viewport, so stray coordinates are safe.

For pixel-by-pixel effects over large areas this is too slow - that is what WritePixelFast between LockBuffer and UnlockBuffer is for.

See also: ReadPixel, WritePixelFast, Plot, LockBuffer.

Example

; WritePixel Example
; ------------------

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

; Build a colour gradient image one pixel at a time.
; WritePixel needs no LockBuffer (see WritePixelFast for the fast version).
img=CreateImage(128,128)
For py=0 To 127
    For px=0 To 127
        ; Pack alpha, red, green and blue into one ARGB value
        argb=$FF000000 Or ((px*2) Shl 16) Or ((py*2) Shl 8) Or (px+py)

        ; Write straight into the image's buffer
        WritePixel px,py,argb,ImageBuffer(img)
    Next
Next

x#=100
y#=80
vx#=3
vy#=2

While Not KeyDown(1)

    Cls

    ; Bounce the finished gradient around the screen
    x=x+vx
    y=y+vy
    If x<0 Or x>512 Then vx=-vx
    If y<40 Or y>352 Then vy=-vy
    DrawImage img,x,y

    Text 0,0,"Esc: exit"
    Text 0,20,"This gradient was drawn with WritePixel, one pixel at a time"

    Flip

Wend

End

Index