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 小时前
虚幻引擎6:Lumen光源技术前瞻
游戏引擎·虚幻
RPGMZ21 小时前
RPGMakerMZ 获取敌人攻击时属性 用于画UI或属性克制
javascript·游戏引擎·rpgmz·rpgmakermz
zdr尽职尽责21 小时前
Untiy 处理Aseprite 资产 解决偏移问题
学习·unity·c#·游戏引擎
LcGero1 天前
游戏引擎Luanti的前世今生与技术解析
游戏引擎·lua·游戏开发·我的世界·luanti
冰凌糕1 天前
Unity3D Shader UV 与纹理采样
unity
郝学胜-神的一滴1 天前
[简化版 GAMES 101] 计算机图形学 06:相机视图矩阵的由来
c++·线性代数·unity·矩阵·godot·图形渲染·unreal engine
XiaoZhangGOGOGO2 天前
《剑来2》动画第二季点映百度网盘提取码_百度网盘提取码资源
unity
惊鸿醉2 天前
基于Kinect SDK的Unity艺术交互展项——完整技术方案
unity
MFXWW22 天前
从 Python 到 3D 开发:Ursina 引擎零基础入门学习路径与核心开发思路
python·游戏引擎·游戏程序·ursina
mxwin2 天前
Unity URP 半透明阴影的局限性
unity·游戏引擎