Question by
wechat_os_Qy0zGVHF5GLFZd1ejN0kk8lf0 · Jul 23, 2020 at 01:41 AM ·
androidtexturetexture2drendertexturereadpixels
Convert Texture to Texture2d takes a lot of time in android device.
I have a function that converting a RGB565 Texture2d to a RGB24Texture2d.
I use Texture2d.ReadPixs() api and it was successfully achieved but when it's running on android It will take 50 milliseconds on Texture2d.ReadPixs() and the readed size is just 640*480.
Is there any other solution to fix it?
Thank you in advance!
public static void textureToTexture2D(Texture texture, Texture2D texture2D)
{
if (texture == null)
throw new ArgumentNullException("texture == null");
if (texture2D == null)
throw new ArgumentNullException("texture2D == null");
if (texture.width != texture2D.width || texture.height != texture2D.height)
throw new ArgumentException("texture and texture2D need to be the same size.");
RenderTexture prevRT = RenderTexture.active;
if (texture is RenderTexture)
{
RenderTexture.active = (RenderTexture)texture;
texture2D.ReadPixels(new UnityEngine.Rect(0f, 0f, texture.width, texture.height), 0, 0, false);
texture2D.Apply(false, false);
}
else
{
RenderTexture tempRT = RenderTexture.GetTemporary(texture.width, texture.height, 0, RenderTextureFormat.ARGB32);
Graphics.Blit(texture, tempRT);
RenderTexture.active = tempRT;
//it takes the most time on the function about 50ms
texture2D.ReadPixels(new UnityEngine.Rect(0f, 0f, texture.width, texture.height), 0, 0, false);
texture2D.Apply(false, false);
RenderTexture.ReleaseTemporary(tempRT);
}
RenderTexture.active = prevRT;
}
Comment
Your answer
Follow this Question
Related Questions
Get Colors from RenderTexture faster! 1 Answer
Trying to Take a Snapshot of Only a Portion of the Screen In-Game 0 Answers
Correct way to modify a Texture2d with a shader? 0 Answers
Rendering Camera to PNG produces completely grey image. 1 Answer
Display Pure Texture Colors with no lighting or reflectiveness . 0 Answers