godot: Viewport save_png does not save Alpha, and get_pixel make crash

Fix https://github.com/godotengine/godot/issues/32894#issuecomment-543290503

Godot version: 3.1.1 stable

OS/device including version: Linux editor and release template

Issue description:

  1. Using save_png on Viewport texture does not save Alpha that Viewport texture has.
  2. Using get_pixel on texture from Viewport make crash**(outside of editor)**

Steps to reproduce:

	var image = fbo.get_texture().get_data()
	image.save_png("1.png") #bug1 no alpha
	print(image.get_pixel(0,0)) #bug2 crash (outside of editor)

Minimal reproduction project: https://danilw.github.io/godot-utils-and-other/BUG_Viewport_image.zip

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (10 by maintainers)

Most upvoted comments

@danilw then the problem maybe comes from save_png()? Viewports can be 16-bit, but Godot only saves 8-bit PNGs. So save_png converts to 8-bits, but perhaps it dropped alpha in the process?

try this instead:

image.convert(Image.FORMAT_RGBA8)
image.save_png(...)

The above is not working for me in 3.4.4 with hdr false and converting to rgba8 (5). Ive tried with tree viewport, an attached viewport for 3d and also another one for 2d. Nothing works. It still captures the background of the environment color, which if I dont use that, I can see my desktop…

Fixed in 4.0.

If you want transparency in 3.2, change the Viewport usage to 2D, because it works for some reason.