我正在开发一个Hololens应用程序,它为用户显示一个带有信息的PNG图像。这些图像是从协程中的StreamingAssets文件夹加载的。问题在于加载这些资产的速度。如果用户循环到另一个页面,应用程序会在PC上瞬间下降到大约1-3 FPS。
我希望你们中的一些人能帮助我想出一些方法来优化这些图像的存储和流式传输。例如,有没有办法以较低的分辨率加载图像,以节省时间和内存(硬件的内存非常有限),并在实际需要显示图像时加载额外的细节?多线程是否会在加载图像时使帧速率更好?
发布于 2017-09-07 23:09:04
因此,程序员在评论中的建议有助于完全消除性能问题。下面的代码是用于在启动时流式输入所需图像的协程。
IEnumerator LoadImages()
{
int oldImgIndx = imageIndex;
imageIndex = 1;
bool thereAreImages = true;
while (thereAreImages && imageIndex < 1000)
{
if (System.IO.File.Exists(CreateFilePath(imageIndex)))
{
string url = "File:///" + CreateFilePath(imageIndex);
Texture2D tex = new Texture2D(4, 4);
WWW www = new WWW(url);
yield return www;
www.LoadImageIntoTexture(tex);
spriteList.Add(Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f)));
imageIndex++;
}
else
{
thereAreImages = false;
}
}
finished = true;
imageIndex = oldImgIndx;
}全息影像的问题出在www.LoadImageIntoTexture(tex);系列上。当在PC端显示多个图像时,这段代码是必需的,但是在Hololens上,一次只显示一个图像,可以省略它。
https://stackoverflow.com/questions/46099021
复制相似问题