ReadPixel.htm 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>ReadPixel (x,y,[buffer])</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. x - x coordinate of pixel <br />
  13. y - y coordinate of pixel <br />
  14. buffer (optional) - name of buffer to read colour value from, e.g. BackBuffer() (defaults to current graphics buffer)
  15. </td>
  16. </tr>
  17. </table>
  18. <h1>Description</h1>
  19. <table>
  20. <tr>
  21. <td>
  22. Reads a color value from either the current buffer or the specified buffer. <br />
  23. <br />
  24. The returned colour value is in the form of an integer that contains the alpha, red, green and blue values of the pixel. <br />
  25. <br />
  26. You can use this command on a locked buffer for a slight speed-up. See LockBuffer. <br />
  27. <br />
  28. Warning: this is a low level command with no error checking for out of range parameters, use with care.
  29. <br>
  30. <br>
  31. See also: <a class=small href=GetColor.htm>GetColor</a>, <a class=small href=ReadPixelFast.htm>ReadPixelFast</a>.
  32. </td>
  33. </tr>
  34. </table>
  35. <h1><a href=../2d_examples/ReadPixel.bb>Example</a></h1>
  36. <table>
  37. <tr>
  38. <td>
  39. ; ReadPixel/WritePixel Example <br />
  40. ; ---------------------------- <br />
  41. <br />
  42. Graphics 640,480,16 <br />
  43. <br />
  44. Print "Press a key to read color values (this may take a few seconds)" <br />
  45. WaitKey() <br />
  46. <br />
  47. ; Load and draw an image on to the screen - can be anything <br />
  48. pic=LoadImage("media/blitz_pic.bmp") <br />
  49. DrawImage pic,0,0 <br />
  50. <br />
  51. ; Initialise an array big enough to fit all the color information of the screen <br />
  52. Dim pix(GraphicsWidth(),GraphicsHeight()) <br />
  53. <br />
  54. ; Use ReadPixel to get all the color information of the screen <br />
  55. For y=0 To GraphicsHeight() <br />
  56. For x=0 To GraphicsWidth() <br />
  57. pix(x,y)=ReadPixel(x,y) <br />
  58. Next <br />
  59. Next <br />
  60. <br />
  61. Cls <br />
  62. Locate 0,0 <br />
  63. Print "Press a key to write pixels (this may takes a few seconds)" <br />
  64. Print "Once this has finished, you can then press a key to end the program" <br />
  65. <br />
  66. WaitKey() <br />
  67. <br />
  68. ; Use WritePixel to redraw the screen using the color information we got earlier <br />
  69. For y=0 To GraphicsHeight() <br />
  70. For x=0 To GraphicsWidth() <br />
  71. WritePixel x,y,pix(x,GraphicsHeight()-y) ; get y array value in backwards order, to flip screen <br />
  72. Next <br />
  73. Next <br />
  74. <br />
  75. WaitKey()
  76. </td>
  77. </tr>
  78. </table>
  79. <br>
  80. <a target=_top href=../index.htm>Index</a><br>
  81. <br>
  82. 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>
  83. </html>