コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: tpxxn/TexExplorer
        private void Open_OnClick(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog
            {
                Filter     = "Klei Texture Files (*.tex)|*.tex|(Klei Xml File)|*.xml|All Files (*.*)|*.*",
                DefaultExt = "tex"
            };

            if (dialog.ShowDialog(this) == true)
            {
                string[] file = dialog.FileName.Split('.');
                if (file[file.Length - 1] == "xml")
                {
                    TexTool     tool  = new TexTool();
                    XmlDocument anxml = new XmlDocument();
                    anxml.LoadXml(File.ReadAllText(dialog.FileName));
                    XmlNode atlas   = anxml.GetElementsByTagName("Atlas")[0];
                    XmlNode texture = atlas.SelectSingleNode("Texture");
                    string  texName = texture.Attributes["filename"].Value;
                    string  dictor  = System.IO.Path.GetDirectoryName(dialog.FileName) + @"\";
                    string  xmlPath = dictor + texName;
                    Console.WriteLine(xmlPath);

                    tool.OpenFile(dialog.SafeFileName, new FileStream(xmlPath, FileMode.Open));
                    int         alterWidth  = tool.CurrentFileRaw.Width;
                    int         alterHeight = tool.CurrentFileRaw.Height;
                    XmlNode     Elements    = atlas.SelectSingleNode("Elements");
                    XmlNodeList elements    = Elements.SelectNodes("Element");
                    foreach (XmlNode node in elements)
                    {
                        string name        = node.Attributes["name"].Value.Split('.')[0] + ".png";
                        float  u1          = Convert.ToSingle(node.Attributes["u1"].Value);
                        float  u2          = Convert.ToSingle(node.Attributes["u2"].Value);
                        float  v1          = Convert.ToSingle(node.Attributes["v1"].Value);
                        float  v2          = Convert.ToSingle(node.Attributes["v2"].Value);
                        int    imageHeight = (int)(alterHeight * v2 - alterHeight * v1);
                        int    imageWidth  = (int)(alterWidth * u2 - alterWidth * u1);
                        Console.WriteLine("(" + (int)(alterWidth * u1) + "," + (int)(alterHeight - (alterHeight * v1) - imageHeight) + ")  (" + (int)(alterWidth * u2) + "," + (int)(alterHeight - alterHeight * v2 + imageHeight) + ")");
                        System.Drawing.Rectangle cloneRect = new System.Drawing.Rectangle((int)(alterWidth * u1), (int)(alterHeight - (alterHeight * v1) - imageHeight), imageWidth, imageHeight);
                        //Rectangle cloneRect = new Rectangle(0, (int)(alterheight - (alterheight * v1) - imageheight), (int)(alterwidth * u2), (int)(alterheight - alterheight * v2 + imageheight));
                        System.Drawing.Imaging.PixelFormat format = tool.CurrentFileRaw.PixelFormat;
                        Bitmap     cloneBitmap = tool.CurrentFileRaw.Clone(cloneRect, format);
                        FileStream wImage      = new FileStream(dictor + name, FileMode.Create);
                        cloneBitmap.Save(wImage, ImageFormat.Png);
                        wImage.Close();
                    }
                    System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("Explorer.exe")
                    {
                        Arguments = "/e,/select," + dialog.FileName
                    };
                    System.Diagnostics.Process.Start(psi);
                    return;
                }
                //backgroundWorker.RunWorkerAsync(dialog);
                OpenFile(dialog);
            }
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: tpxxn/TexExplorer
 public MainWindow()
 {
     InitializeComponent();
     backgroundWorker.DoWork             += BackgroundWorker_DoWork;
     backgroundWorker.RunWorkerCompleted += BackgroundWorker_RunWorkerCompleted;
     Tool               = new TexTool();
     Tool.FileOpened   += Tool_FileOpened;
     Tool.FileRawImage += Tool_FileRawImage;
     GridSizeWidthTextBox.VerifyFunc  = UnitVerifyFunc;
     GridSizeHeightTextBox.VerifyFunc = UnitVerifyFunc;
     ViewModel             = ViewModelLocator.Current.Main;
     VersionTextBlock.Text = $"版本: {Assembly.GetExecutingAssembly().GetName().Version}";
     if (!string.IsNullOrEmpty(Global.OpenInPath))
     {
         Tool.OpenFile(Global.OpenInPath, new FileStream(Global.OpenInPath, FileMode.Open, FileAccess.Read));
     }
 }
コード例 #3
0
ファイル: App.xaml.cs プロジェクト: tpxxn/TexExplorer
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var args = e.Args;

            if (args.Length == 1) // 打开为
            {
                Global.OpenInPath = args[0];
            }
            else if (args.Length == 2) // 命令行
            {
                var inputFile  = args[0];
                var outputFile = args[1];
                var tool       = new TexTool();
                tool.FileRawImage += (s, ev) =>
                {
                    tool.SaveFile(outputFile);
                };
                tool.OpenFile(inputFile, new FileStream(inputFile, FileMode.Open, FileAccess.Read));
                Current.Shutdown();
            }
        }