How to save an image without compression

Godot Version

3.5

Question

How to save an Image without compression or filtered

when I save a file, it loses quality. This is due to compression or filtering. Well, in any case, I just need to ensure that the quality is not lost while maintaining it!

Image image = HisViewPort.GetTexture().GetData();
image.Convert(Image.Format.Rgba8);
image.SavePng(“res://” + cycles + “.png”);

Try GetImage() instead of GetData()? I don’t think textures have that method anyway???

GetImage()… there is no such function anywhere, I even checked the documentation there too.

oh, right, 3.5, sorry

Well, no dice, it’s not something in the code you posted and there are no notes in the docs, so if you’re seeing a viewport on screen it should be saved lossless afaik. What happens if you skip the convert? Can you provide a screenshot and the saved image for comparison?

6

png is lossless format… only data compression, not visual like jpg

this is cube? from viewport? left side is ambient and right side is light?

and what exactly is meant by compression? data compression or visual compression?

I think there is no compression here. But in any case, my question was whether it was possible to save the image from viewports somehow. Without loss of quality? I gave a small script above

Also HisViewPort.TransparentBg = true;

I work still 3.2.3 version of godot… but is still 3.x :wink:

this is my piece of code how I saved image and data are ok…
maybe no convert data from viewport but copy to Image.new()

func generate_image( color: Color, filename: String ):
	var img = Image.new()
	img.create( 320, 240, false, Image.FORMAT_RGB8 )
	img.fill(color)
	img.save_png(filename)

I found this , try this

extends Node

@onready var captured_image = $CapturedImage

func _on_CaptureButton_pressed():
	# Retrieve the captured image.
	var img = get_viewport().get_texture().get_image()

	# Create a texture for it.
	var tex = ImageTexture.create_from_image(img)

	# Set the texture to the captured image node.
	captured_image.set_texture(tex)

get_image() not’s in 3.5

ok, then you try create texture, put data from viewport and save as png

float lossy_quality = 0.7

  • void set_lossy_storage_quality ( float value )
  • float get_lossy_storage_quality ( )

The storage quality for STORAGE_COMPRESS_LOSSY.

thanks for the help. I think I’ve found an alternative for myself.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.