Reading Image Buffers
BlitzPlus Forums/BlitzPlus Programming/Reading Image Buffers
| ||
Could someone please explain to me, why the below snippet of code fails ?
heightmap=LoadImage("testh.bmp")
offset#=256/225
For y=1 To 255
For x=1 To 255
a=ReadPixel(xmap#,ymap#,heightmap)
xmap#=xmap#+offset#
Next
ymap#=ymap#+offset#
xmap#=0
Next
I'm using this in B3D to load in a pic and read off the heightmap data - but its bringing up the error 'Buffer does not exist - a=ReadPixel(xmap#,ymap#,heightmap)' Thanks Paul. |
| ||
| ReadPixel (as well ReadPixelFast) need an image buffer to work with. So you should first set the image buffer: setbuffer imagebuffer(heightmap) then lock the buffer with the command lockbuffer At the end of the process, use UnlockBuffer. Hope this helps, Sergio. |
| ||
Thanks Semar, tried the alterations.. still reporting that the buffer does not exist ?.
heightmap=LoadImage("testh.bmp")
offset#=256/225
SetBuffer ImageBuffer(heightmap)
LockBuffer heightmap
For y=1 To 255
For x=1 To 255
a=ReadPixel(xmap#,ymap#,heightmap)
xmap#=xmap#+offset#
Next
ymap#=ymap#+offset#
xmap#=0
Next
UnlockBuffer heightmap
Now fails at the lockbuffer command. !? |
| ||
| Only thing i can think of is the heightmap image doesn't exist. |
| ||
| If only that was the problem :( it does exist. Although I'm using Blitz3d - this wouldnt/shouldnt effect these types of image commands should it ??? |
| ||
another thing tho, might be unrelatedoffset#=256/225 try offset#=256.0/225.0 For some reason it gives back an integer unless you state the number as a float. I'm at college so can't test it. |
| ||
heightmap=LoadImage("testh.bmp")
hBuffer = ImageBuffer(heightmap)
LockBuffer hBuffer
For y=1 To 255 ; probably want 0 to 255.
For x=1 To 255
a=ReadPixel(x,y,hBuffer)
; do something with returned value
Next
; likewise...
Next
UnlockBuffer hBuffer
|
| ||
| Thanks Floyd :) .. and Robs just posted up a nice link to some RGB functions in the 3d forum. I think I was somehow getting my image and texture banks mixed up. |