Hi,
I want to save the texture of my RawImage but the result is inverted.
I try to apply a uvRect to flip the image before saving and, I see to image flip on screen, but the image.jpg is still inverted. No mater what I do with the uvRect I see no change on image.jpg.
There is my code :
Texture2D TextureToTexture2D(Texture texture)
{
Texture2D texture2D = new Texture2D(texture.width, texture.height, TextureFormat.RGBA32, false);
RenderTexture currentRT = RenderTexture.active;
RenderTexture renderTexture = RenderTexture.GetTemporary(texture.width, texture.height, 32);
Graphics.Blit(texture, renderTexture);
RenderTexture.active = renderTexture;
texture2D.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
texture2D.Apply();
//texture2D = FlipTexture(texture2D);
RenderTexture.active = currentRT;
RenderTexture.ReleaseTemporary(renderTexture);
return texture2D;
}
myRawImage.uvRect = new Rect(myRawImage.uvRect.x, myRawImage.uvRect.y, myRawImage.uvRect.width, -myRawImage.uvRect.height);
Texture2D textureToSave = TextureToTexture2D(myRawImage.texture);
byte[] bytes = textureToSave.EncodeToJPG();
System.IO.File.WriteAllBytes(@"C:\Test\" + "Image_JPG.jpg", bytes);
break;