private void ApplyMonochromeConversion(ZebraGraphics graphics, PrintType printType, MonochromeConversion monochromeConversionType) { JobStatusControl.UpdateLog("Converting graphic..."); if (printType != PrintType.MonoK && printType != PrintType.GrayDye) { switch (monochromeConversionType) { case MonochromeConversion.Diffusion: JobStatusControl.UpdateLog("Ignoring diffusion option for non-mono/gray format type..."); break; case MonochromeConversion.HalfTone_6x6: case MonochromeConversion.HalfTone_8x8: JobStatusControl.UpdateLog("Ignoring halftone option for non-mono/gray format type..."); break; } } else { switch (monochromeConversionType) { case MonochromeConversion.Diffusion: graphics.MonochromeConverionType = MonochromeConversion.Diffusion; JobStatusControl.UpdateLog("Applying diffusion algorithm..."); break; case MonochromeConversion.HalfTone_6x6: graphics.MonochromeConverionType = MonochromeConversion.HalfTone_6x6; JobStatusControl.UpdateLog("Applying 6x6 halftone algorithm..."); break; case MonochromeConversion.HalfTone_8x8: graphics.MonochromeConverionType = MonochromeConversion.HalfTone_8x8; JobStatusControl.UpdateLog("Applying 8x8 halftone algorithm..."); break; } } }
private async void ConvertButton_Click(object sender, RoutedEventArgs e) { JobStatusControl.ClearLog(); await Task.Run(() => { try { using (ZebraGraphics graphics = new ZebraCardGraphics(null)) { graphics.PrinterModel = viewModel.SelectedPrinterModelInfo.PrinterModel; if (!Path.IsPathRooted(viewModel.OriginalGraphicFilename)) { throw new ArgumentException("Original graphic filename must be an absolute path"); } System.Drawing.Image image = ImageHelper.CreateImageFromFile(viewModel.OriginalGraphicFilename); byte[] imageData = ImageHelper.ConvertImage(image); int width; // Width of final output image int height; // Height of final output image switch (viewModel.SelectedDimensionOption) { case DimensionOption.Crop: int croppedWidth = ConstrainWidth(viewModel.Width, viewModel.SelectedPrinterModelInfo.MaxWidth); int croppedHeight = ConstrainHeight(viewModel.Height, viewModel.SelectedPrinterModelInfo.MaxHeight); imageData = CropImage(graphics, imageData, croppedWidth, croppedHeight); width = croppedWidth; height = croppedHeight; break; case DimensionOption.Resize: width = ConstrainWidth(viewModel.Width, viewModel.SelectedPrinterModelInfo.MaxWidth); height = ConstrainHeight(viewModel.Height, viewModel.SelectedPrinterModelInfo.MaxHeight); JobStatusControl.UpdateLog($"Resizing image to {width}x{height}..."); break; case DimensionOption.Original: default: width = ConstrainWidth(image.Width, viewModel.SelectedPrinterModelInfo.MaxWidth); height = ConstrainHeight(image.Height, viewModel.SelectedPrinterModelInfo.MaxHeight); JobStatusControl.UpdateLog("Keeping current image dimensions unless they exceed the maximum model-specific width and height..."); break; } GraphicsFormat graphicsFormat = viewModel.SelectedGraphicsFormat; MonochromeConversion monochromeConversionType = viewModel.SelectedGraphicsFormat.GetMonochromeConversion(); PrintType printType = viewModel.SelectedGraphicsFormat.GetPrintType(); OrientationType orientationType = OrientationType.Landscape; JobStatusControl.UpdateLog($"Setting orientation to {orientationType}..."); graphics.Initialize(width, height, orientationType, printType, System.Drawing.Color.White); graphics.DrawImage(imageData, 0, 0, width, height, RotationType.RotateNoneFlipNone); ApplyMonochromeConversion(graphics, printType, monochromeConversionType); JobStatusControl.UpdateLog($"Writing graphic file to path {viewModel.ConvertedGraphicFilename}..."); WriteToFile(viewModel.ConvertedGraphicFilename, graphics.CreateImage().ImageData); JobStatusControl.UpdateLog("Finished converting graphic"); } } catch (Exception exception) { string errorMessage = $"Error converting graphic: {exception.Message}"; JobStatusControl.UpdateLog(errorMessage); MessageBoxHelper.ShowError(errorMessage); } }); }
internal GraphicsFormatAttribute(string displayName, MonochromeConversion monochromeConversion, PrintType printType) { DisplayName = displayName; MonochromeConversion = monochromeConversion; PrintType = printType; }