84 lines
2.5 KiB
HTML
84 lines
2.5 KiB
HTML
<html>
|
|
<head>
|
|
<title>Blitz3D Docs</title>
|
|
<link rel=stylesheet href=../css/commands.css type=text/css>
|
|
</head>
|
|
<body>
|
|
<h1>ReadPixel (x,y,[buffer])</h1>
|
|
<h1>Parameters</h1>
|
|
<table>
|
|
<tr>
|
|
<td>
|
|
x - x coordinate of pixel
|
|
<br />
|
|
y - y coordinate of pixel
|
|
<br />
|
|
buffer (optional) - name of buffer to read colour value from, e.g. BackBuffer() (defaults to current graphics buffer)
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<h1>Description</h1>
|
|
<table>
|
|
<tr>
|
|
<td>
|
|
Reads a color value from either the current buffer or the specified buffer.
|
|
|
|
<br />
|
|
|
|
<br />
|
|
The returned colour value is in the form of an integer that contains the alpha, red, green and blue values of the pixel.
|
|
|
|
<br />
|
|
|
|
<br />
|
|
You can use this command on a locked buffer for a slight speed-up. See LockBuffer.
|
|
|
|
<br />
|
|
|
|
<br />
|
|
Warning: this is a low level command with no error checking for out of range parameters, use with care.
|
|
<br>
|
|
<br>
|
|
See also: <a class=small href=GetColor.htm>GetColor</a>, <a class=small href=ReadPixelFast.htm>ReadPixelFast</a>.
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<h1><a href=../2d_examples/ReadPixel.bb>Example</a></h1>
|
|
<table>
|
|
<tr>
|
|
<td>
|
|
; ReadPixel/WritePixel Example
|
|
<br />
|
|
; ----------------------------
|
|
<br />
|
|
|
|
<br />
|
|
Graphics 640,480,16
|
|
<br />
|
|
|
|
<br />
|
|
Print "Press a key to read color values (this may take a few seconds)"
|
|
<br />
|
|
WaitKey()
|
|
<br />
|
|
|
|
<br />
|
|
; Load and draw an image on to the screen - can be anything
|
|
<br />
|
|
pic=LoadImage("media/blitz_pic.bmp")
|
|
<br />
|
|
DrawImage pic,0,0
|
|
<br />
|
|
|
|
<br />
|
|
; Initialise an array big enough to fit all the color information of the screen
|
|
<br />
|
|
Dim pix(GraphicsWidth(),GraphicsHeight())
|
|
<br />
|
|
|
|
<br />
|
|
; Use ReadPixel to get all the color information of the screen
|
|
<br />
|
|
For y=0 To GraphicsHeight()
|
|
<br />
|
|
For x=0 To GraphicsWidth()
|
|
<br />
|
|
pix(x,y)=ReadPixel(x,y)
|
|
<br />
|
|
Next
|
|
<br />
|
|
Next
|
|
<br />
|
|
|
|
<br />
|
|
Cls
|
|
<br />
|
|
Locate 0,0
|
|
<br />
|
|
Print "Press a key to write pixels (this may takes a few seconds)"
|
|
<br />
|
|
Print "Once this has finished, you can then press a key to end the program"
|
|
<br />
|
|
|
|
<br />
|
|
WaitKey()
|
|
<br />
|
|
|
|
<br />
|
|
; Use WritePixel to redraw the screen using the color information we got earlier
|
|
<br />
|
|
For y=0 To GraphicsHeight()
|
|
<br />
|
|
For x=0 To GraphicsWidth()
|
|
<br />
|
|
WritePixel x,y,pix(x,GraphicsHeight()-y) ; get y array value in backwards order, to flip screen
|
|
<br />
|
|
Next
|
|
<br />
|
|
Next
|
|
<br />
|
|
|
|
<br />
|
|
WaitKey()
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<br>
|
|
<a target=_top href=../index.htm>Index</a><br>
|
|
<br>
|
|
Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=ReadPixel&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
|
|
</html>
|