Pete1995
6 months agoChannel Surfer
Strange Bitmap Update Behavior
I fail to understand the rules for updating Draw2D ops. My expectation is that bm.Finish() should update any cached drawing ops. However, when I GetByteArray(), there is nothing there. The following is a minimal working example. I do a Clear(). DrawRect(), Finish(), GetByteArray() and then manually write a value into the red byte. Then I print the byteArray. It's "empty", except the red value.
I display the bitmap and it looks as expected (minus the red pixel, of course). I GetByteArray() again, and now the Draw2D stuff is there! Do I misunderstand bm.Finish()? Or is this a bug?
Sub Main()
pixWidth = 10
bytesPerPix = 4
bytesPerRow = (pixWidth * bytesPerPix)
printRow = 3
screen = CreateObject("roScreen")
bm = CreateObject("roBitmap", {width:pixWidth, height:10, AlphaEnable:true, name:"test"})
bm.clear( &h808080FF)
bm.DrawRect( 2, 2, 6, 6, &hFFFFFFFF)
bm.Finish()
ba = bm.GetByteArray( 0, 0, pixWidth, 10)
ba[ (printRow * bytesPerRow) + (4 * bytesPerPix)] = &hFF
' Set index to start of 4th row. Setup to read a line of 10 pixels
indx = printRow * (pixWidth * bytesPerPix)
print "i"; TAB(16)"Red";TAB(22)"Grn";TAB(28)"Blu";TAB(34)"Alp"
for i = 0 to (pixWidth-1)
r = ba[indx ] : g = ba[indx+1] : b = ba[indx+2] : a = ba[indx+3]
print indx; TAB(16)r;TAB(22)g;TAB(28)b;TAB(34)a
indx += 4
endfor
screen.DrawObject( 0, 0, bm)
screen.SwapBuffers()
sleep(5000)
ba = bm.GetByteArray( 0, 0, pixWidth, 10)
print "i"; TAB(16)"Red";TAB(22)"Grn";TAB(28)"Blu";TAB(34)"Alp"
for i = 0 to (pixWidth-1)
r = ba[indx ] : g = ba[indx+1] : b = ba[indx+2] : a = ba[indx+3]
print indx; TAB(16)r;TAB(22)g;TAB(28)b;TAB(34)a
indx += 4
endfor
Any insight would be helpful.