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);
     }
 }
Example #3
0
            private void ExportSingleImage(IPresentationImage image, ExportImageParams exportParams)
            {
                image = GetImageForExport(image);

                string fileName = _fileNamingStrategy.GetSingleImageFileName(image, FileExtension);

                SelectedImageExporter.Export(image, fileName, exportParams);

                ReportProgress(fileName, ++_progress);
            }
Example #4
0
        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);
        }
Example #5
0
            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);
                }
            }
Example #6
0
        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();
            }
        }
Example #7
0
            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) || !(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);
 }