I have ui.Image1 with Mask component and ui.Image2 that is placed inside ui.Image1, then I want to save the result to Texture2d to save the resulting image to png.

Sprite sprite = sourceImage.sprite;
Texture2D newText = new Texture2D((int)sprite.rect.width,(int)sprite.rect.height);
Color[] newColors = sprite.texture.GetPixels((int)sprite.textureRect.x,
                                             (int)sprite.textureRect.height );

System.IO.File.WriteAllBytes(_SavePath + "photo.png", newText.EncodeToPNG());

but I have the error:

Texture 'mask' is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings.

If I change the texture type of 'mask' from Sprite to Advanced - the mask stop work. Let me know what need to do.


You must log in to answer this question.

Browse other questions tagged .