Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Gary_CHAN |
I am now making a game which divides a texture into several equal parts ( like 4 parts) and change the pixel’s color values and save it in the user:// folder for later use (for example loading it on a new game using load() and set it as the texture_normal of a TextureRect). I am using the following code:
var old_texture = load(res://test_image.png)
var old_image = old_texture.get_data()
var new_image = old_image.get_rect(Rect2(starting_point, image_area ))
new_image.convert(Image.FORMAT_RGBA8)
new_image.lock()
for x_coordinate in range(tab_start_x):
for y_coordinate in range(tab_height):
new_image.set_pixel(x_coordinate, y_coordinate, Color(0,0,0,0))
new_image.unlock()
var new_texture = ImageTexture.new()
new_texture.create_from_image(new_image)
ResourceSaver.save("user://Save/1.tres, new_texture)
It did the job but the final file size(.tres) is huge. For testing, I used a png file with 256px*256px which is 162KB. The .stex file is 152KB. But the output four .tres files are 2.30MB in total. I try converting the new_image into different format but it seems to have no impact on file size.
I then compress the new_image using
new_image.compress(0,0,0.2)
it did the job too by shrinking the file size but the console shows an error
“ERROR: compress: Condition ’ !_image_compress_bc_func ’ is true. returned: ERR_UNAVAILABLE
At: core/image.cpp:1809”
It only appears if I export the project. If I run it in editor, it will shows no error and compress the file as expected.
I would like to ask two questions:
1, How can I making a smaller image ( at least has similar file size with the original image)?
2, What does the error mean? I didn’t find ppl talking about this error but I don’t understand the source code in github.