コード例 #1
0
        private void SelectOutput(object sender, RoutedEventArgs routedEventArgs)
        {
            if (_processing)
            {
                MessageBox.Show(ScanlationTools.Resources.BusyPleaseAwait, ScanlationTools.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);

                return;
            }

            var menuItem = (MenuItem)sender;

            switch (menuItem.Name)
            {
            case "OutputPNG":
                OutputJPG.IsChecked   = false;
                OutputPSD.IsChecked   = false;
                _selectedOutputFormat = SelectableOutputFormats.PNG;
                break;

            case "OutputJPG":
                OutputPNG.IsChecked   = false;
                OutputPSD.IsChecked   = false;
                _selectedOutputFormat = SelectableOutputFormats.JPG;
                break;

            case "OutputPSD":
                OutputPNG.IsChecked   = false;
                OutputJPG.IsChecked   = false;
                _selectedOutputFormat = SelectableOutputFormats.PSD;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(menuItem.Name), menuItem.Name, null);
            }
        }
コード例 #2
0
ファイル: ImageIO.cs プロジェクト: Dinokin/ScanlationTools
        public static async Task SaveImages(IEnumerable <MagickImage> images, SelectableOutputFormats format, DirectoryInfo location, IProgress <ushort>?progressReporter = null) => await Task.WhenAll(
            images.Select((image, iterator) => Task.Run(() =>
        {
            string fileName;
            MagickFormat finalFormat;

            image.Quality = 100;
            image.Alpha(AlphaOption.Remove);
            image.BackgroundColor = MagickColor.FromRgb(255, 255, 255);
            if (image.DetermineColorType() == ColorType.Grayscale)
            {
                image.Grayscale();
            }

            if (iterator < 9)
            {
                fileName = $"00{iterator + 1}";
            }
            else if (iterator < 99)
            {
                fileName = $"0{iterator + 1}";
            }
            else
            {
                fileName = $"{iterator + 1}";
            }

            switch (format)
            {
            case SelectableOutputFormats.JPG:
                finalFormat = MagickFormat.Jpg;
                fileName   += ".jpg";
                break;

            case SelectableOutputFormats.PNG:
                finalFormat = image.ColorType == ColorType.Grayscale ? MagickFormat.Png8 : MagickFormat.Png24;
                fileName   += ".png";
                break;

            case SelectableOutputFormats.PSD:
                finalFormat = MagickFormat.Psd;
                fileName   += ".psd";
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(format), format, null);
            }

            image.Write($"{location}{Path.DirectorySeparatorChar}{fileName}", finalFormat);
            progressReporter?.Report(1);
        })));