protected static void Export(IPresentationImage image, string filePath, ExportImageParams exportParams, ImageCodecInfo encoder, EncoderParameters encoderParameters) { using (Bitmap bmp = DrawToBitmap(image, exportParams)) { Export(bmp, filePath, encoder, encoderParameters); } }
protected static void Export(IPresentationImage image, string filePath, ExportImageParams exportParams, ImageFormat imageFormat) { using (Bitmap bmp = DrawToBitmap(image, exportParams)) { Export(bmp, filePath, imageFormat); } }
protected static void Export(IPresentationImage image, string filePath, ExportImageParams exportParams, ImageCodecInfo encoder, EncoderParameters encoderParameters) { using (Bitmap bmp = DrawToBitmap(image, exportParams)) { // try to save the dpi in the meta header for image types that support it (the GDI+ implementation of TIFF encoder doesn't even though TIFF itself supports it) bmp.SetResolution(exportParams.Dpi, exportParams.Dpi); Export(bmp, filePath, encoder, encoderParameters); } }
private void ExportSingleImage(IPresentationImage image, ExportImageParams exportParams) { image = GetImageForExport(image); string fileName = _fileNamingStrategy.GetSingleImageFileName(image, FileExtension); SelectedImageExporter.Export(image, fileName, exportParams); ReportProgress(fileName, ++_progress); }
private void ExportImages(IBackgroundTaskContext context, ref List <IPresentationImage> imagesToDispose) { ExportImageParams exportParams = new ExportImageParams(); exportParams.Scale = Scale; exportParams.ExportOption = _exportOption; exportParams.DisplayRectangle = _clipboardItem.DisplayRectangle; exportParams.SizeMode = SizeMode; exportParams.OutputSize = new Size(Width, Height); exportParams.BackgroundColor = BackgroundColor; using (Avi.VideoStreamWriter writer = new Avi.VideoStreamWriter(_selectedCodec)) { if (!UseDefaultQuality) { writer.Quality = _quality; } for (int i = 0; i < NumberOfImages; ++i) { if (context != null && context.CancelRequested) { break; } if (context != null) { int number = i + 1; string message = String.Format(SR.MessageFormatExportingFrame, number, NumberOfImages); ReportProgress(context, message, number); } IPresentationImage image = ImageExporter.ClonePresentationImage(DisplaySet.PresentationImages[i]); imagesToDispose.Add(image); using (Bitmap bitmap = ImageExporter.DrawToBitmap(image, exportParams)) { if (!writer.IsOpen) { //many codecs (like DivX) expect width and/or height to be divisible by 4. int width = NormalizeDimension(bitmap.Width); int height = NormalizeDimension(bitmap.Height); writer.Width = width; writer.Height = height; writer.FrameRate = this.FrameRate; writer.Open(this.FilePath); } writer.AddBitmap(bitmap); } } } }
private ExportImageParams GetExportParams(ClipboardItem clipboardItem) { ExportImageParams exportParams = new ExportImageParams(); exportParams.ExportOption = ExportOption; exportParams.DisplayRectangle = clipboardItem.DisplayRectangle; exportParams.Scale = Scale; exportParams.SizeMode = SizeMode; exportParams.OutputSize = new Size(Width, Height); exportParams.BackgroundColor = BackgroundColor; return(exportParams); }
private void ExportDisplaySet(IDisplaySet displaySet, ExportImageParams exportParams) { foreach (ImageFileNamePair pair in _fileNamingStrategy.GetImagesAndFileNames(displaySet, FileExtension)) { if (IsAsynchronous && _taskContext.CancelRequested) { break; } IPresentationImage image = GetImageForExport(pair.Image); SelectedImageExporter.Export(image, pair.FileName, exportParams); ReportProgress(pair.FileName, ++_progress); } }
private void Export() { if (SelectedImageExporter == null) { throw new InvalidOperationException("No exporter was chosen; unable to export any images."); } if (NumberOfImagesToExport == 1) { EventResult result = EventResult.Success; AuditedInstances exportedInstances = GetInstancesForAudit(ItemsToExport, this.ExportFilePath); try { if (!Directory.Exists(Path.GetDirectoryName(ExportFilePath ?? ""))) { throw new FileNotFoundException("The specified export file path does not exist: " + ExportFilePath ?? ""); } ClipboardItem clipboardItem = (ClipboardItem)_itemsToExport[0]; ExportImageParams exportParams = GetExportParams(clipboardItem); SelectedImageExporter.Export((IPresentationImage)clipboardItem.Item, ExportFilePath, exportParams); } catch (Exception ex) { result = EventResult.SeriousFailure; Platform.Log(LogLevel.Error, ex); } finally { AuditHelper.LogExportStudies(exportedInstances, EventSource.CurrentUser, result); } } else { if (!Directory.Exists(ExportFilePath ?? "")) { throw new FileNotFoundException("The specified export directory does not exist." + ExportFilePath ?? ""); } _multipleImageExporter = new MultipleImageExporter(this); _multipleImageExporter.Run(); } }
private void Export() { ReportProgress(SR.MessageExportingImages, _progress); foreach (ClipboardItem clipboardItem in ItemsToExport) { if (IsAsynchronous && _taskContext.CancelRequested) { break; } ExportImageParams exportParams = GetExportParams(clipboardItem); if (clipboardItem.Item is IPresentationImage) { ExportSingleImage((IPresentationImage)clipboardItem.Item, exportParams); } else if (clipboardItem.Item is IDisplaySet) { ExportDisplaySet((IDisplaySet)clipboardItem.Item, exportParams); } } if (IsAsynchronous) { if (_taskContext.CancelRequested) { ReportProgress(SR.MessageCancelled, _progress); _taskContext.Cancel(); } else { ReportProgress(SR.MessageExportComplete, _progress); _taskContext.Complete(); } } }
public static Bitmap DrawToBitmap(IPresentationImage image, ExportImageParams exportParams) { Platform.CheckForNullReference(image, "image"); Platform.CheckForNullReference(exportParams, "exportParams"); if (!(image is ISpatialTransformProvider)) throw new ArgumentException("The image must have a valid ImageSpatialTransform in order to be exported."); if (exportParams.ExportOption == ExportOption.TrueSize) { var imageSopProvider = image as IImageSopProvider; var pixelSpacing = imageSopProvider == null ? null : imageSopProvider.Frame.NormalizedPixelSpacing; if (pixelSpacing == null || pixelSpacing.IsNull) throw new ArgumentException("The image does not contain pixel spacing information. TrueSize export is not possible."); } IImageSpatialTransform transform = ((ISpatialTransformProvider) image).SpatialTransform as IImageSpatialTransform; if (transform == null) throw new ArgumentException("The image must have a valid ImageSpatialTransform in order to be exported."); if (exportParams.ExportOption == ExportOption.TrueSize) return DrawTrueSizeImageToBitmap(image, exportParams.OutputSize, exportParams.Dpi); if (exportParams.SizeMode == SizeMode.Scale) { // TODO: Refactor ImageExporter, so there only the displayRectangle and OutputRectangle are provided // Scale can be automatically figured out. // A "Padded" option can be provided to distinguish between the current Fixed and ScaleToFit options // TODO: Refactor ImageExporter, so there are separate exporters for each ExportOption. // The ExportImageParams is getting too many options and not all of them are applicable to each exporter // Instead, each exporter should have its own parameters. if (exportParams.ExportOption == ExportOption.Wysiwyg) { return DrawWysiwygImageToBitmap(image, exportParams.DisplayRectangle, exportParams.Scale, exportParams.Dpi); } else { return DrawCompleteImageToBitmap(image, exportParams.Scale, exportParams.Dpi); } } else if (exportParams.SizeMode == SizeMode.ScaleToFit) { if (exportParams.ExportOption == ExportOption.Wysiwyg) { var scale = ScaleToFit(exportParams.DisplayRectangle.Size, exportParams.OutputSize); return DrawWysiwygImageToBitmap(image, exportParams.DisplayRectangle, scale, exportParams.Dpi); } else { var scale = ScaleToFit(image.SceneSize, exportParams.OutputSize); return DrawCompleteImageToBitmap(image, scale, exportParams.Dpi); } } else { Bitmap paddedImage = new Bitmap(exportParams.OutputSize.Width, exportParams.OutputSize.Height); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(paddedImage)) { // paint background using (Brush b = new SolidBrush(exportParams.BackgroundColor)) { graphics.FillRectangle(b, new Rectangle(Point.Empty, exportParams.OutputSize)); } // paint image portion Bitmap bmp; if (exportParams.ExportOption == ExportOption.Wysiwyg) { float scale = ScaleToFit(exportParams.DisplayRectangle.Size, exportParams.OutputSize); bmp = DrawWysiwygImageToBitmap(image, exportParams.DisplayRectangle, scale, exportParams.Dpi); } else { float scale = ScaleToFit(image.SceneSize, exportParams.OutputSize); bmp = DrawCompleteImageToBitmap(image, scale, exportParams.Dpi); } graphics.DrawImageUnscaledAndClipped(bmp, new Rectangle(CenterRectangles(bmp.Size, exportParams.OutputSize), bmp.Size)); bmp.Dispose(); } return paddedImage; } }
public abstract void Export(IPresentationImage image, string filePath, ExportImageParams exportParams);
protected static void Export(IPresentationImage image, string filePath, ExportImageParams exportParams, ImageCodecInfo encoder, EncoderParameters encoderParameters) { using (Bitmap bmp = DrawToBitmap(image, exportParams)) { // try to save the dpi in the meta header for image types that support it (the GDI+ implementation of TIFF encoder doesn't even though TIFF itself supports it) bmp.SetResolution(exportParams.Dpi, exportParams.Dpi); Export(bmp, filePath, encoder, encoderParameters); } }
private void ExportDisplaySet(IDisplaySet displaySet, ExportImageParams exportParams) { foreach (ImageFileNamePair pair in _fileNamingStrategy.GetImagesAndFileNames(displaySet, FileExtension)) { if (IsAsynchronous && _taskContext.CancelRequested) break; IPresentationImage image = GetImageForExport(pair.Image); SelectedImageExporter.Export(image, pair.FileName, exportParams); ReportProgress(pair.FileName, ++_progress); } }
private void ExportSingleImage(IPresentationImage image, ExportImageParams exportParams) { image = GetImageForExport(image); string fileName = _fileNamingStrategy.GetSingleImageFileName(image, FileExtension); SelectedImageExporter.Export(image, fileName, exportParams); ReportProgress(fileName, ++_progress); }
protected static void Export(IPresentationImage image, string filePath, ExportImageParams exportParams, ImageCodecInfo encoder, EncoderParameters encoderParameters) { using (Bitmap bmp = DrawToBitmap(image, exportParams)) { Export(bmp, filePath, encoder, encoderParameters); } }
protected static void Export(IPresentationImage image, string filePath, ExportImageParams exportParams, ImageFormat imageFormat) { using (Bitmap bmp = DrawToBitmap(image, exportParams)) { Export(bmp, filePath, imageFormat); } }
public override void Export(IPresentationImage image, string filePath, ExportImageParams exportParams) { Export(image, filePath, exportParams, _imageFormat); }
public static Bitmap DrawToBitmap(IPresentationImage image, ExportImageParams exportParams) { Platform.CheckForNullReference(image, "image"); Platform.CheckForNullReference(exportParams, "exportParams"); if (!(image is ISpatialTransformProvider) || !(image is IImageGraphicProvider)) { throw new ArgumentException("The image must implement IImageGraphicProvider and have a valid ImageSpatialTransform in order to be exported."); } if (exportParams.ExportOption == ExportOption.TrueSize) { var imageSopProvider = image as IImageSopProvider; var pixelSpacing = imageSopProvider == null ? null : imageSopProvider.Frame.NormalizedPixelSpacing; if (pixelSpacing == null || pixelSpacing.IsNull) { throw new ArgumentException("The image does not contain pixel spacing information. TrueSize export is not possible."); } } ImageSpatialTransform transform = ((ISpatialTransformProvider)image).SpatialTransform as ImageSpatialTransform; if (transform == null) { throw new ArgumentException("The image must have a valid ImageSpatialTransform in order to be exported."); } if (exportParams.ExportOption == ExportOption.TrueSize) { return(DrawTrueSizeImageToBitmap(image, exportParams.OutputSize, exportParams.Dpi)); } if (exportParams.SizeMode == SizeMode.Scale) { // TODO: Refactor ImageExporter, so there only the displayRectangle and OutputRectangle are provided // Scale can be automatically figured out. // A "Padded" option can be provided to distinguish between the current Fixed and ScaleToFit options // TODO: Refactor ImageExporter, so there are separate exporters for each ExportOption. // The ExportImageParams is getting too many options and not all of them are applicable to each exporter // Instead, each exporter should have its own parameters. if (exportParams.ExportOption == ExportOption.Wysiwyg) { return(DrawWysiwygImageToBitmap(image, exportParams.DisplayRectangle, exportParams.Scale, exportParams.Dpi)); } else { return(DrawCompleteImageToBitmap(image, exportParams.Scale, exportParams.Dpi)); } } else if (exportParams.SizeMode == SizeMode.ScaleToFit) { if (exportParams.ExportOption == ExportOption.Wysiwyg) { var scale = ScaleToFit(exportParams.DisplayRectangle.Size, exportParams.OutputSize); return(DrawWysiwygImageToBitmap(image, exportParams.DisplayRectangle, scale, exportParams.Dpi)); } else { var sourceImage = (IImageGraphicProvider)image; var scale = ScaleToFit(new Size(sourceImage.ImageGraphic.Columns, sourceImage.ImageGraphic.Rows), exportParams.OutputSize); return(DrawCompleteImageToBitmap(image, scale, exportParams.Dpi)); } } else { Bitmap paddedImage = new Bitmap(exportParams.OutputSize.Width, exportParams.OutputSize.Height); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(paddedImage)) { // paint background using (Brush b = new SolidBrush(exportParams.BackgroundColor)) { graphics.FillRectangle(b, new Rectangle(Point.Empty, exportParams.OutputSize)); } // paint image portion Bitmap bmp; if (exportParams.ExportOption == ExportOption.Wysiwyg) { float scale = ScaleToFit(exportParams.DisplayRectangle.Size, exportParams.OutputSize); bmp = DrawWysiwygImageToBitmap(image, exportParams.DisplayRectangle, scale, exportParams.Dpi); } else { IImageGraphicProvider sourceImage = (IImageGraphicProvider)image; float scale = ScaleToFit(new Size(sourceImage.ImageGraphic.Columns, sourceImage.ImageGraphic.Rows), exportParams.OutputSize); bmp = DrawCompleteImageToBitmap(image, scale, exportParams.Dpi); } graphics.DrawImageUnscaledAndClipped(bmp, new Rectangle(CenterRectangles(bmp.Size, exportParams.OutputSize), bmp.Size)); bmp.Dispose(); } return(paddedImage); } }
public abstract void Export(IPresentationImage image, string filePath, ExportImageParams exportParams);
public override void Export(IPresentationImage image, string filePath, ExportImageParams exportParams) { Export(image, filePath, exportParams, _imageFormat); }