@@ -14,6 +14,7 @@ public partial class TextureViewer : Form
1414 {
1515 Bitmap image ;
1616
17+ string loadedFileName ;
1718 bool loaded ;
1819 float x , y ;
1920 int width , height ;
@@ -66,6 +67,7 @@ public TextureViewer(AssetsFileInstance inst, AssetTypeValueField baseField)
6667 {
6768 string fmtName = ( ( TextureFormat ) tf . m_TextureFormat ) . ToString ( ) . Replace ( "_" , " " ) ;
6869 Text = $ "Texture Viewer [{ fmtName } ]";
70+ loadedFileName = tf . m_Name ;
6971
7072 image = new Bitmap ( tf . m_Width , tf . m_Height , PixelFormat . Format32bppArgb ) ;
7173
@@ -124,6 +126,30 @@ private void TextureViewer_FormClosed(object sender, FormClosedEventArgs e)
124126 }
125127 }
126128
129+ public void SaveTexture ( )
130+ {
131+ if ( image == null )
132+ {
133+ return ;
134+ }
135+ SaveFileDialog texSaveDialog = new SaveFileDialog ( ) ;
136+ texSaveDialog . Filter = ".PNG File|*.png" ;
137+ texSaveDialog . Title = "Save texture as .PNG file" ;
138+ texSaveDialog . FileName = loadedFileName ;
139+ DialogResult res = texSaveDialog . ShowDialog ( ) ;
140+ string selectedName = texSaveDialog . FileName ;
141+ if ( res == DialogResult . Cancel || res == DialogResult . No || string . IsNullOrWhiteSpace ( selectedName ) )
142+ {
143+ return ;
144+ }
145+ if ( File . Exists ( selectedName ) )
146+ {
147+ File . Delete ( selectedName ) ;
148+ }
149+ image . Save ( selectedName , ImageFormat . Png ) ;
150+ MessageBox . Show ( "Done!" ) ;
151+ }
152+
127153 private void TextureViewer_Paint ( object sender , PaintEventArgs e )
128154 {
129155 Graphics g = e . Graphics ;
0 commit comments