Saving UI Image to file with transparent background

I need help in understand what i need to do to save an image properly.

Right now i’ve manged to save my UI image, and then load it from file and into a sprite.
but the problem is, the image that i take, also contains the background of the element i wanted to save.

So what should i do in order to only show my character in the saved picture, without anything else?

Right now this is how i save:

var tex = new Texture2D((int)width, (int)height, TextureFormat.RGB24, false);

tex.ReadPixels(new Rect(corners[0].x, corners[0].y, width, height), 0, 0);

If you use a camera to take the picture than set the camera’s “clear flags” to don’t clear.

Pretty sure your Texture format its wrong. Assuming where ever you’re reading the pixels from has an alpha channel you need to use

Texture2D tex = new Texture2D((int)width, (int)height, TextureFormat.ARGB32, false);

Also ensure you save via


As jpegs can’t have alpha channels

Not sure if its the same thing but in Photoshop you can save out an image with transparent areas as PNG and import that into Unity as a UI Sprite.