ReadPixelFast.htm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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>ReadPixelFast (x,y,[buffer])</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. x - y-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()
  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, and returns it. <br />
  23. <br />
  24. The returned colour value is in the form of an integer than contains the alpha, red, green and blue values of the pixel. <br />
  25. <br />
  26. IMPORTANT: <br />
  27. <br />
  28. You *must* use this command on a locked buffer, otherwise the command will fail. See LockBuffer. <br />
  29. <br />
  30. Also, you must make sure that the coordinates that you are reading from are valid, otherwise you will end up reading garbage values. <br />
  31. <br />
  32. WARNING: <br />
  33. <br />
  34. By not following the above advice, you may cause your computer to crash. <br />
  35. <br />
  36. See also: GetColor, ReadPixel.
  37. </td>
  38. </tr>
  39. </table>
  40. <h1><a href=../2d_examples/ReadPixelFast.bb>Example</a></h1>
  41. <table>
  42. <tr>
  43. <td>
  44. ; ReadPixelFast/WritePixeFast Example <br />
  45. ; ----------------------------------- <br />
  46. <br />
  47. Graphics 640,480,16 <br />
  48. <br />
  49. Print "Press a key to read color values" <br />
  50. WaitKey() <br />
  51. <br />
  52. ; Load and draw an image on to the screen - can be anything <br />
  53. pic=LoadImage("media/blitz_pic.bmp") <br />
  54. DrawImage pic,0,0 <br />
  55. <br />
  56. ; Initialise an array big enough to fit all the color information of the screen <br />
  57. Dim pix(GraphicsWidth(),GraphicsHeight()) <br />
  58. <br />
  59. ; Lock buffer before using ReadPixelFast <br />
  60. LockBuffer <br />
  61. <br />
  62. ; Use ReadPixel to get all the color information of the screen <br />
  63. For y=0 To GraphicsHeight() <br />
  64. For x=0 To GraphicsWidth() <br />
  65. pix(x,y)=ReadPixelFast(x,y) <br />
  66. Next <br />
  67. Next <br />
  68. <br />
  69. ; Lock buffer after using ReadPixelFast <br />
  70. UnlockBuffer <br />
  71. <br />
  72. Cls <br />
  73. Locate 0,0 <br />
  74. Print "Press a key to write pixels" <br />
  75. Print "Once this has finished, you can then press a key to end the program" <br />
  76. <br />
  77. WaitKey() <br />
  78. <br />
  79. ; Lock buffer before using WritePixelFast <br />
  80. LockBuffer <br />
  81. <br />
  82. ; Use WritePixel to redraw the screen using the color information we got earlier <br />
  83. For y=0 To GraphicsHeight() <br />
  84. For x=0 To GraphicsWidth() <br />
  85. WritePixelFast x,y,pix(x,GraphicsHeight()-y) ; get y array value in backwards order, to flip screen <br />
  86. Next <br />
  87. Next <br />
  88. <br />
  89. ; Unlock buffer after using WritePixelFast <br />
  90. UnlockBuffer <br />
  91. <br />
  92. WaitKey() <br />
  93. </td>
  94. </tr>
  95. </table>
  96. <br>
  97. <a target=_top href=../index.htm>Index</a><br>
  98. <br>
  99. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=ReadPixelFast&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  100. </html>