对接face++面部识别 sdk的时候需要将T2D转成字节数组发送出去,当然如果是要做图片的本地缓存,也是一样要使用字节数组进行储存的,这时候图片就需要解压 这里介绍了一种解压图片的方法,但是首先你的图片素材必须要可读写
、、、
public Texture2D DeCompress(Texture2D source)
{
RenderTexture renderTex = RenderTexture.GetTemporary(
source.width,
source.height,
0,
RenderTextureFormat.Default,
RenderTextureReadWrite.Linear);
Graphics.Blit(source, renderTex);
RenderTexture previous = RenderTexture.active;
RenderTexture.active = renderTex;
Texture2D readableText = new Texture2D(source.width, source.height);
readableText.ReadPixels(new Rect(0, 0, renderTex.width, renderTex.height), 0, 0);
readableText.Apply();
RenderTexture.active = previous;
RenderTexture.ReleaseTemporary(renderTex);
return readableText;
}
、、、
有了这个方法就可以解压图片,然后用EncodeToPNG()或EncodeToJPG()转字节数组了
\
byte[] imgByte = DeCompress(texture).EncodeToPNG();
\\