Created
November 14, 2024 02:08
-
-
Save tedliou/2d474c4023372dee64a894447363020b to your computer and use it in GitHub Desktop.
Convert Texture2D to PNG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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