Skip to content

Instantly share code, notes, and snippets.

@tedliou
Created November 14, 2024 02:08
Show Gist options
  • Save tedliou/2d474c4023372dee64a894447363020b to your computer and use it in GitHub Desktop.
Save tedliou/2d474c4023372dee64a894447363020b to your computer and use it in GitHub Desktop.
Convert Texture2D to PNG
using System.IO;
using UnityEditor;
using UnityEngine;
public static class Texture2DUtils
{
[MenuItem("Assets/ConvertToPNG")]
public static void ConvertToPNG()
{
var tx2d = Selection.activeObject as Texture2D;
var bytes = tx2d.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/" + Selection.activeObject.name + ".png", bytes);
AssetDatabase.Refresh();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment