白泽图

  • 文章
    • Unity渲染
    • Unity项目开发
    • 工具
    • 数学
    • 算法
    • 网站搭建
    • 网络&操作系统
蒋程个人博客
互联网技术经验总结&分享
  1. 首页
  2. Unity项目开发
  3. 正文

获取Unity UnReadable Texture

2022-04-29 1048点热度 0人点赞 0条评论

从assetbundle中获取的Texture2D 的 isReadable 属性是 false,无法直接读取,下面的方法可以将 isReadable 为false的Texture2D提取出来

using System.IO;
using UnityEditor;
using UnityEngine;

public class SaveUnReadableTexture
{
    [MenuItem(("Tools/Save UnReadable Texture"))]
    static void Save()
    {
        var texture = EditorGUIUtility.TrIconContent("d_AnimatorController Icon").image;
        RenderTexture tmp = RenderTexture.GetTemporary(
                    texture.width,
                    texture.height,
                    0,
                    RenderTextureFormat.Default,
                    RenderTextureReadWrite.Linear);

        Graphics.Blit(texture, tmp);
        RenderTexture previous = RenderTexture.active;
        RenderTexture.active = tmp;

        Texture2D newTexture2D = new Texture2D(texture.width, texture.height);
        newTexture2D.ReadPixels(new Rect(0, 0, tmp.width, tmp.height), 0, 0);
        newTexture2D.Apply();

        Debug.LogError(newTexture2D.isReadable);
        RenderTexture.active = previous;

        var imgSavePath = Path.Combine(Application.dataPath, texture.name + ".png");
        var bytes = newTexture2D.EncodeToPNG();
        var file = File.Open(imgSavePath, FileMode.CreateNew);
        var binary = new BinaryWriter(file);
        binary.Write(bytes);
        file.Close();
    }
}

提取如下:

相关应用:https://www.bzetu.com/371/.html

本文参考:https://support.unity.com/hc/en-us/articles/206486626-How-can-I-get-pixels-from-unreadable-textures-

标签: 暂无
最后更新:2022-04-29

蒋程

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

您需要 登录 之后才可以评论

COPYRIGHT © 2023 白泽图. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

登录
注册|忘记密码?