WritePixelFast.htm 2.8 KB

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