Screehshot (display.captureScreen) behaiviour

Somewhere I read that it is possible to make the whole screen blurry. A blurry background is a good base for a menu. The idea is to make a screenshot, and then apply a filter. Works for me well. Here is a simple code.

local Top_Menu_group
Top_Menu_group = display.newGroup()




function top_menu_button_click(event)
	if event.phase == "ended" then
		-- Capture the screen
		local Screen_shot
		Top_Menu_group:removeSelf()
		Top_Menu_group = display.newGroup()
		-- first phase
    		Screen_shot = display.captureScreen( false )
		Screen_shot.x = display.contentCenterX
		Screen_shot.y = display.contentCenterY
		Screen_shot.fill.effect = "filter.grayscale"
		local Screen_shot2 = display.captureScreen( false )
		-- phase 2 (Possibly, there is a way how to apply TWO filters...)
		Screen_shot2.fill.effect = "filter.blurGaussian"
 		Screen_shot2.fill.effect.horizontal.blurSize = 20
		Screen_shot2.fill.effect.horizontal.sigma = 50
		Screen_shot2.fill.effect.vertical.blurSize = 20
		Screen_shot2.fill.effect.vertical.sigma = 50

		Screen_shot2.x = display.contentCenterX
		Screen_shot2.y = display.contentCenterY
		Screen_shot:removeSelf()
		Top_Menu_group:insert(Screen_shot2)
	end
end

The result looks wonderful! Now on top of it I can draw a colorful menu.

But, there is just a small peculiarity, must be a bug. If at this stage I suspend and then resume the application. On a real device the Screen_shot2 object just disappears revealing the real background. But in the emulator everything is OK, the Screen_shot2 is still there.

The situation does not change if I avoid using a display-group. Also, I got no function to monitor suspend/resume events, so there is no code which works with the mentioned objects.

Build 2020.3601

Android

When an app is suspended, the Android OS removes all OpenGL textures from memory. When the app is resumed, Corona must reload all images, but the capture image no longer exists in memory.

https://docs.coronalabs.com/api/library/display/captureScreen.html#gotchas

After that quote, docs also offer a workaround. You should take a look at that.

2 Likes

Thank you :fleur_de_lis:

I just thought that it would be good that in emulator of a device and on a real device things would work similarly…

If I knew my way around the engine source code, I could have implemented this though I assume this was on purpose. It seems that the specific API has different gotchas for every other platform. Instead of making it work skin-specific, they probably thought it was a good idea to encourage device testing.

I supply this kind of feature in SSK2: https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/misc/#easyblur

Works the same in simulator and on device. I haven’t run on an emulator however.

Note: Now however I’ll have to go and verify this after a suspend/resume. Interesting.

1 Like