On Android, saving a render image to a memblock, and then creating an image from the memblock doesn't work.
This is another demo (Paul's demo written for SpectrePaul) tweaked to demonstrate the problem. The numbers on the screen show that all the pixels are saved in the memblock as 0, after the header which is intact.
Run on Windows and you will see lots of data after clicking the text
Run on Android and you will see zeros.
It then displays the grabbed image - good on windows and black on Android.
Could somebody else please confirm? I tried on 2 Android devices.
Global w,h,rw,rh,screenTop as integer
w = 800
h = 1280
rw = 800
rh = 1280
Global sw#, sh# as float
sw# = w/rw
sh# = h/rh
screenTop=0 // Change this to position drawing screen height
SetWindowTitle( "Render to Memblock" )
SetScreenResolution( w, h)
SetSyncRate( 60, 0 )
SetVirtualResolution( w, h )
SetScissor( 0, 0, 0, 0 )
SetClearColor(0,0,0)
SetPrintSize(20)
// create two render targets and swap between them
global buffer as integer[1]
buffer[0] = CreateRenderImage( 512, 1024, 0, 0 ) // currently render targets must be a power of 2
buffer[1] = CreateRenderImage( 512, 1024, 0, 0 ) // luckily they don't have to match the current screen size to work
global currBuffer as integer = 0
// clear them both
SetRenderToImage( buffer[currBuffer], 0 )
ClearScreen()
SetRenderToImage( buffer[1-currBuffer], 0 )
ClearScreen()
SetRenderToScreen()
// create the screen sprite, this will be used to display the final image and draw the
// background of the next render image
global screen as integer
screen = CreateSprite(buffer[currBuffer])
SetSpriteDepth(screen,1000)
SetSpriteTransparency(screen,0)
// these positions only matter if you have black borders, the render image will also have
// them so the sprite displaying it must be in the true top left corner of the screen
// if you can guarantee no black borders then you can use 0,0 and w,h
SetSpritePosition(screen,GetScreenBoundsLeft(),GetScreenBoundsTop())
SetSpriteSize(screen, GetScreenBoundsRight()-GetScreenBoundsLeft(),GetScreenBoundsBottom()-GetScreenBoundsTop())
Global Brush as integer
Brush = CreateSprite(0)
SetSpriteSize(brush,128,128)
SetSpriteOffset(brush, GetSpriteWidth(brush)/2,GetSpriteHeight(brush)/2)
SetSpriteColorAlpha(brush, 60)
SetSpritePosition(brush,-200,0)
SetSpriteVisible(Brush,0)
text = CreateText("Click Here to save from memblock")
SetTextSize(text,30)
SetTextPosition(text,20,20)
//paint some colour in the top left
for n = 1 to 100
SetSpriteColor(brush, Random(0,255), Random(0,255), Random(0,255), 255)
paint(random(1,500), random(1,500))
next n
Do
Print("FPS:"+str(ScreenFPS(),0))
if getpointerpressed()
SetSpriteColor(brush, Random(0,255), Random(0,255), Random(0,255), 255)
endif
if GetPointerReleased() = 1
if GetTextHitTest(text, getPointerX(), getPointerY()) = 1
mb = CreateMemblockFromImage(buffer[currbuffer])
im = CreateImageFromMemblock(mb)
SetSpriteVisible(screen,0)
sp = CreateSprite(im)
SetSpriteSize(sp, GetVirtualWidth() * 0.8, GetVirtualHeight() * 0.8)
SetSpritePositionbyOffset(sp,GetVirtualWidth() * 0.5, GetVirtualHeight() * 0.66)
sync()
while GetPointerReleased() = 0
SetTextVisible(text,0)
print("This is not the sprite you are looking for...")
for n = 1 to 10
txt$ = ""
for m = 1 to 20
txt$ = txt$ + str(GetMemblockByte(mb, ((n-1) * 20) + m - 1)) + ","
next m
print (txt$)
next n
sync()
endwhile
end
endif
endif
if GetPointerState()=1
x = GetPointerX()
y = GetPointerY()
Paint(x,y)
endif
sync()
Loop
function Paint(x,y)
// Draw the current screen with the old render image onto the new render image
// Draw the new brush onto the new render image
// Set the new render image as the screen image and swap the buffers ready to do it again
// make sure the background image is in the right place just in case
SetSpriteImage( screen, buffer[1-currBuffer] )
SetSpritePosition(screen,GetScreenBoundsLeft(),GetScreenBoundsTop())
SetSpriteSize(screen, GetScreenBoundsRight()-GetScreenBoundsLeft(),GetScreenBoundsBottom()-GetScreenBoundsTop())
// clear the image and draw the background (the current scene)
SetRenderToImage( buffer[currBuffer], 0 )
ClearScreen()
DrawSprite(screen)
// draw the new brush
SetSpritePositionByOffset(Brush,x,y)
SetSpriteAngle(Brush, random(0,360))
SetSpriteVisible(Brush,1)
DrawSprite(Brush)
SetSpriteVisible(Brush,0)
SetRenderToScreen()
// set the new render image as the current scene and swap the buffers for next time
SetSpriteImage( screen, buffer[currBuffer] )
currBuffer = 1-currBuffer
endfunction