Example #1
0
        public static void Start(BitmapMakerArgs args)
        {
            var dirName  = DateTime.Now.ToString("yyyyMMdd-HHmmss");
            var fileName = Path.GetFileNameWithoutExtension(args.FileName);

            if (string.IsNullOrWhiteSpace(fileName))
            {
                fileName = DateTime.Now.ToString("ffffff");
            }
            var extension = Path.GetExtension(args.FileName);

            if (string.IsNullOrWhiteSpace(extension))
            {
                extension = ".png";
            }
            var scaleTransform = new ScaleTransform();

            args.Element.RenderTransform = scaleTransform;
            args.Element.UpdateLayout();

            // Create the directory to deploy image files to.
            Directory.CreateDirectory(dirName);

            // Save an image file for the original image.
            SaveAsImage(args.Element, scaleTransform, dirName, fileName, extension);

            // Save image files for the original image and the specified sizes.
            foreach (var size in args.ImageSizes)
            {
                SaveAsImage(args.Element, scaleTransform, dirName, fileName, extension, false, size);
            }

            if (args.CreateBlackVersion)
            {
                // Blacken elements on the canvas.
                SetBlackImage(args.Element);

                // Save an image file for the blackened image.
                SaveAsImage(args.Element, scaleTransform, dirName, fileName, extension, true);

                // Save image files for the blackened image and the specified sizes.
                foreach (var size in args.ImageSizes)
                {
                    SaveAsImage(args.Element, scaleTransform, dirName, fileName, extension, true, size);
                }
            }

            // Open the directory that image files have been deployed to.
            var filePath_original = CreateFilePath(dirName, fileName, extension);

            Process.Start("explorer", string.Format("/select,\"{0}\"", filePath_original));
            Application.Current.Shutdown();
        }
Example #2
0
        public static void Start(BitmapMakerArgs args)
        {
            var dirName = DateTime.Now.ToString("yyyyMMdd-HHmmss");
            var fileName = Path.GetFileNameWithoutExtension(args.FileName);
            if (string.IsNullOrWhiteSpace(fileName))
            {
                fileName = DateTime.Now.ToString("ffffff");
            }
            var extension = Path.GetExtension(args.FileName);
            if (string.IsNullOrWhiteSpace(extension))
            {
                extension = ".png";
            }
            var scaleTransform = new ScaleTransform();
            args.Element.RenderTransform = scaleTransform;
            args.Element.UpdateLayout();

            // Create the directory to deploy image files to.
            Directory.CreateDirectory(dirName);

            // Save an image file for the original image.
            SaveAsImage(args.Element, scaleTransform, dirName, fileName, extension);

            // Save image files for the original image and the specified sizes.
            foreach (var size in args.ImageSizes)
            {
                SaveAsImage(args.Element, scaleTransform, dirName, fileName, extension, false, size);
            }

            if (args.CreateBlackVersion)
            {
                // Blacken elements on the canvas.
                SetBlackImage(args.Element);

                // Save an image file for the blackened image.
                SaveAsImage(args.Element, scaleTransform, dirName, fileName, extension, true);

                // Save image files for the blackened image and the specified sizes.
                foreach (var size in args.ImageSizes)
                {
                    SaveAsImage(args.Element, scaleTransform, dirName, fileName, extension, true, size);
                }
            }

            // Open the directory that image files have been deployed to.
            var filePath_original = CreateFilePath(dirName, fileName, extension);
            Process.Start("explorer", string.Format("/select,\"{0}\"", filePath_original));
            Application.Current.Shutdown();
        }
Example #3
0
 void MainWindow_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         var args = new BitmapMakerArgs
         {
             Element            = MainCanvas,
             FileName           = FileNameText.Text,
             CreateBlackVersion = CreateBlackCheck.IsChecked == true,
             ImageSizes         = ImageSizeList.Items.OfType <Size>().ToArray(),
         };
         BitmapMaker.Start(args);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "XAML to Image");
         Close();
     }
 }
Example #4
0
 void MainWindow_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         var args = new BitmapMakerArgs
         {
             Element = MainCanvas,
             FileName = FileNameText.Text,
             CreateBlackVersion = CreateBlackCheck.IsChecked == true,
             ImageSizes = ImageSizeList.Items.OfType<Size>().ToArray(),
         };
         BitmapMaker.Start(args);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "XAML to Image");
         Close();
     }
 }