Esempio n. 1
0
 private void ExportImage_PostExecute(SaveImageResults obj)
 {
     IsBusy = false;
 }
 private void ExportImage_PostExecute(SaveImageResults obj)
 {
     IsBusy = false;
 }
Esempio n. 3
0
        private Task <SaveImageResults> ExportImage_Execute(TargetImage targetImage)
        {
            var busyPickingFile = MainResources.Busy_PickingFile;
            var busySavingImage = MainResources.Busy_SavingImage;

            BitmapSource target;

            switch (targetImage)
            {
            case TargetImage.Top:
                target = ViewModel.Textures.Top.Bitmap;
                break;

            case TargetImage.Bottom:
                target = ViewModel.Textures.Bottom.Bitmap;
                break;

            case TargetImage.FileLarge:
                target = ViewModel.Textures.FileLarge.Bitmap;
                break;

            case TargetImage.FileSmall:
                target = ViewModel.Textures.FileSmall.Bitmap;
                break;

            case TargetImage.FolderOpen:
                target = ViewModel.Textures.FolderOpen.Bitmap;
                break;

            case TargetImage.FolderClosed:
                target = ViewModel.Textures.FolderClosed.Bitmap;
                break;

            case TargetImage.TopAlt:
                target = ViewModel.Textures.TopAlt.Bitmap;
                break;

            case TargetImage.SmallIcon:
                target = ViewModel.Info.SmallIcon.Bitmap;
                break;

            case TargetImage.LargeIcon:
                target = ViewModel.Info.LargeIcon.Bitmap;
                break;

            default:
                throw new IndexOutOfRangeException();
            }

            var task = new Task <SaveImageResults>(() =>
            {
                BusyText = busyPickingFile;
                var svfl = new SaveFileDialog
                {
                    Filter   = "PNG Files|*.png",
                    FileName = targetImage.ToString().ToLower()
                };
                var dlg = svfl.ShowDialog();
                SaveImageResults results = new SaveImageResults
                {
                    Saved  = false,
                    Target = targetImage,
                    Path   = svfl.FileName
                };

                if (!dlg.HasValue || dlg.Value)
                {
                    BusyText = busySavingImage;
                    try
                    {
                        PngBitmapEncoder encoder = new PngBitmapEncoder();
                        encoder.Frames.Add(BitmapFrame.Create(target));
                        using (var fs = File.Open(results.Path, FileMode.Create))
                        {
                            encoder.Save(fs);
                            results.Saved = true;
                        }
                    }
                    catch
                    {
                        // Ignore;
                    }
                }
                return(results);
            });

            task.Start();
            return(task);
        }
        private Task<SaveImageResults> ExportImage_Execute(TargetImage targetImage)
        {
            var busyPickingFile = MainResources.Busy_PickingFile;
            var busySavingImage = MainResources.Busy_SavingImage;

            BitmapSource target;
            switch (targetImage)
            {
                case TargetImage.Top:
                    target = ViewModel.Textures.Top.Bitmap;
                    break;
                case TargetImage.Bottom:
                    target = ViewModel.Textures.Bottom.Bitmap;
                    break;
                case TargetImage.FileLarge:
                    target = ViewModel.Textures.FileLarge.Bitmap;
                    break;
                case TargetImage.FileSmall:
                    target = ViewModel.Textures.FileSmall.Bitmap;
                    break;
                case TargetImage.FolderOpen:
                    target = ViewModel.Textures.FolderOpen.Bitmap;
                    break;
                case TargetImage.FolderClosed:
                    target = ViewModel.Textures.FolderClosed.Bitmap;
                    break;
                case TargetImage.TopAlt:
                    target = ViewModel.Textures.TopAlt.Bitmap;
                    break;
                default:
                    throw new IndexOutOfRangeException();
            }

            var task = new Task<SaveImageResults>(() =>
            {
                BusyText = busyPickingFile;
                var svfl = new SaveFileDialog
                {
                    Filter = "PNG Files|*.png",
                    FileName = targetImage.ToString().ToLower()
                };
                var dlg = svfl.ShowDialog();
                SaveImageResults results = new SaveImageResults
                {
                    Saved = false,
                    Target = targetImage,
                    Path = svfl.FileName
                };

                if (!dlg.HasValue || dlg.Value)
                {
                    BusyText = busySavingImage;
                    try
                    {
                        PngBitmapEncoder encoder = new PngBitmapEncoder();
                        encoder.Frames.Add(BitmapFrame.Create(target));
                        using (var fs = File.Open(results.Path, FileMode.Create))
                        {
                            encoder.Save(fs);
                            results.Saved = true;
                        }
                    }
                    catch
                    {
                        // Ignore;
                    }
                }
                return results;
            });
            task.Start();
            return task;
        }