Hello,
I wanted to know how to get pixels from an external texture (plugin : EasyMovieTexture).
Currently, I'm using this function :
private Texture2D GetReadableTexture(Texture2D tex)
{
if (myTexture2D == null)
myTexture2D = new Texture2D(tex.width, tex.height);
// https://support.unity3d.com/hc/en-us/articles/206486626-How-can-I-get-pixels-from-unreadable-textures-
RenderTexture tmp = RenderTexture.GetTemporary(
tex.width,
tex.height,
0,
RenderTextureFormat.Default,
RenderTextureReadWrite.Linear);
Graphics.Blit(tex, tmp);
RenderTexture previous = RenderTexture.active;
RenderTexture.active = tmp;
myTexture2D.ReadPixels(new Rect(0, 0, tmp.width, tmp.height), 0, 0);
//myTexture2D.Apply(); // no need
RenderTexture.active = previous;
RenderTexture.ReleaseTemporary(tmp);
return myTexture2D;
}
It returns a readable texture from the external texture. It works. But it is quite slow, and creates a lot of garbage with the GetPixels() that will be done after.
Is there a way to get the texture pixel for Editor/Android, we assume that we are using OpenGL. (has someone done it?) Is it possible without creating a native plugin (tried it, crashes everytime ^^')
My final goal is to get the average color of the image (video frame).
Thanks in advance,
Sylafrs
↧