Hi,
I’m building an editor for a 2d avatar with UI Images, where I change the sprite and color out of a list with different options.
Here is an example:

The problem is to save the images as one png-file.
I tried to create a new texture with ReadPixels from screen like the screenshot example from the docs:
Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
texture.Apply();
byte[] bytes = texture.EncodeToPNG();
File.WriteAllBytes(Application.persistentDataPath + "/avatar.png", bytes);
With this method the result image is dependent of the screensize and not the source sprites of 1024x1024px. So I get e.g. 357x659px images.
Another approach was to get the source textures and lerp all the pixels:
Texture2D texture = new Texture2D(texture_1.width, texture_1.height);
for (int i = 0; i < texture.width; i++)
{
for (int j = 0; j < texture.height; j++)
{
Color tex1_color = texture_1.GetPixel(i, j);
Color tex2_color = texture_2.GetPixel(i, j);
Color merged_color = Color.Lerp(tex1_color, tex2_color, tex2_color.a / 1);
texture.SetPixel(i, j, merged_color);
}
}
texture.Apply();
byte[] bytes = texture.EncodeToPNG();
File.WriteAllBytes(Application.persistentDataPath + "/avatar.png", bytes);
But with this method the original colors of the sprites (in this case all default white) are saved and not the colors of the ui image component which is customized. And because there are about 15 images it takes some time to merge all one after another.
Is there a possibility to save the sprites with the color from image component to a single png with original size of the sprites?
