private void Import_Click(object sender, RoutedEventArgs e)
        {
            UndertaleEmbeddedTexture target = DataContext as UndertaleEmbeddedTexture;

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.DefaultExt = ".png";
            dlg.Filter     = "PNG files (.png)|*.png|All files|*";

            if (dlg.ShowDialog() == true)
            {
                try
                {
                    Bitmap bmp;
                    using (var ms = new MemoryStream(TextureWorker.ReadTextureBlob(dlg.FileName)))
                    {
                        bmp = new Bitmap(ms);
                    }
                    bmp.SetResolution(96.0F, 96.0F);
                    using (var stream = new MemoryStream())
                    {
                        bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                        target.TextureData.TextureBlob = stream.ToArray();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to import file: " + ex.Message, "Failed to import file", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
예제 #2
0
        private void Import_Click(object sender, RoutedEventArgs e)
        {
            UndertaleEmbeddedTexture target = DataContext as UndertaleEmbeddedTexture;

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.DefaultExt = ".png";
            dlg.Filter     = "PNG files (.png)|*.png|All files|*";

            if (dlg.ShowDialog() == true)
            {
                try
                {
                    Bitmap bmp;
                    using (var ms = new MemoryStream(TextureWorker.ReadTextureBlob(dlg.FileName)))
                    {
                        bmp = new Bitmap(ms);
                    }
                    bmp.SetResolution(96.0F, 96.0F);

                    var width  = (uint)bmp.Width;
                    var height = (uint)bmp.Height;

                    if ((width & (width - 1)) != 0 || (height & (height - 1)) != 0)
                    {
                        mainWindow.ShowWarning("WARNING: texture page dimensions are not powers of 2. Sprite blurring is very likely in game.", "Unexpected texture dimensions");
                    }

                    using (var stream = new MemoryStream())
                    {
                        bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                        target.TextureData.TextureBlob = stream.ToArray();

                        TexWidth.GetBindingExpression(TextBox.TextProperty)?.UpdateTarget();
                        TexHeight.GetBindingExpression(TextBox.TextProperty)?.UpdateTarget();
                    }
                }
                catch (Exception ex)
                {
                    mainWindow.ShowError("Failed to import file: " + ex.Message, "Failed to import file");
                }
            }
        }
예제 #3
0
        private void Import_Click(object sender, RoutedEventArgs e)
        {
            UndertaleEmbeddedTexture target = DataContext as UndertaleEmbeddedTexture;

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.DefaultExt = ".png";
            dlg.Filter     = "PNG files (.png)|*.png|All files|*";

            if (dlg.ShowDialog() == true)
            {
                try
                {
                    target.TextureData.TextureBlob = TextureWorker.ReadTextureBlob(dlg.FileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to import file: " + ex.Message, "Failed to import file", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }