Unity Texture2D读取像素时出错问题

Texture2D在读取像素处理时,经常会出错,这个时候可以用如下函数先转换:

cs 复制代码
	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;
    }
相关推荐
我写代码菜如坤7 小时前
unity获取键盘按键
unity·计算机外设·游戏引擎
q5673152310 小时前
Python 3.x 下的 3D 游戏引擎
开发语言·后端·python·3d·django·游戏引擎
LhcyyVSO13 小时前
【毛发教程】使用 Maya、XGen 和虚幻引擎创建马尾辫发型
游戏引擎·虚幻·云渲染·动画渲染·maya·渲染农场·xgen
雪 狼13 小时前
unity 使用UnityWebRequest从服务器下载
服务器·unity·游戏引擎
Unity打怪升级20 小时前
Unity入门之重要组件和API(3) : Transform
unity·c#·游戏引擎
Unity游戏开发1 天前
【Unity navigation面板】
unity·游戏引擎
程序员正茂1 天前
Unity游戏帧率查看软件Fraps
unity·帧率
Unity游戏开发1 天前
【Unity navmeshaggent 组件】
unity·游戏引擎
瞄喵1 天前
HumbleBundle7月虚幻捆绑包30件军事题材美术模型沙漠自然环境大逃杀模块化建筑可定制武器包二战现代坦克飞机道具丧尸士兵角色模型20240705
游戏引擎·虚幻
陈言必行2 天前
Unity 资源 之 Sweet Cakes Icon套装,110个高品质蛋糕图标分享
unity·游戏引擎