【问题标题】:Texture from Assets folder to Texture2D and the save?从 Assets 文件夹到 Texture2D 的纹理并保存?
【发布时间】:2014-07-15 07:15:07
【问题描述】:

我在 Assets 文件夹中有一个纹理 (Texture Type = Advanced, Read/Write Enabled = true, Max Size = 512, Format = RGB 24 bit)。现在我想读取这个纹理,然后将像素复制到另一个 texture2d 中并保存。

private Texture2D sourceImg;

...

Texture2D tex = new Texture2D(512, 512, TextureFormat.RGB24, false);
tex.SetPixels(sourceImg.GetPixels(0,0,512,512));
tex.Apply();
byte[] png = tex.EncodeToPNG();
File.WriteAllBytes(Application.persistentDataPath + "/Screenshot.png", png);

我不知道,为什么这个简单的代码不起作用?

当我将新的 tex 添加到一个四边形时:

quad.renderer.material.mainTexture = tex;

有效。

【问题讨论】:

    标签: unity3d textures texture2d


    【解决方案1】:

    好的,我解决了。只需这样做:转到编辑 -> 项目设置 -> 播放器 -> 其他设置并将写入权限更改为外部。

    【讨论】:

      【解决方案2】:

      谢谢!为我工作。建议改变这个: File.WriteAllBytes(Application.persistentDataPath + "/Screenshot.png", png); 通过自定义输出文件夹,如下所示: File.WriteAllBytes("C:/OutputFolder" + "/Screenshot.png", png);

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-11-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多