相关疑难解决方法(0)

从 Texture2D 创建 UI 图像

我正在开发一个实时流应用程序,该应用程序接收JPEG图像作为字节数组并将其显示在屏幕上UI.Image。它工作正常,但我正在优化并且几乎没有问题。目前,代码我具有低于转换字节数组到Texture2D随后创建一个Sprite从所述Texture2D然后分配Sprite到UI.Iamge显示在屏幕上。

Texture2D camTexture;
Image screenDisplay;
public byte[] JPEG_VIDEO_STREAM;
bool updateScreen = false;
Run Code Online (Sandbox Code Playgroud)

//初始化

JPEG_VIDEO_STREAM = new byte[20000];
camTexture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
Run Code Online (Sandbox Code Playgroud)

//在更新函数中运行的主要代码

if(updateScreen){
camTexture.LoadImage(JPEG_VIDEO_STREAM);
Sprite tempSprite = Sprite.Create(camTexture, new Rect(0, 0, camTexture.width, camTexture.height), Vector2.zero, 0);
screenDisplay.sprite = tempSprite;
updateScreen = false;
}
Run Code Online (Sandbox Code Playgroud)

上面的代码目前执行 3 个步骤只是为了将图像显示到屏幕上。

byte array …

c# optimization performance unity-game-engine

5
推荐指数
1
解决办法
9037
查看次数

标签 统计

c# ×1

optimization ×1

performance ×1

unity-game-engine ×1