コード例 #1
0
ファイル: ImageBoxExtensions.cs プロジェクト: aerik/fo-dicom
        /// <summary>
        /// Prints an image box onto the specified graphics.
        /// </summary>
        /// <param name="imageBox">Image box to print.</param>
        /// <param name="graphics">Graphics in which image box should be contained.</param>
        /// <param name="box">Rectangle within which the image box should be contained.</param>
        /// <param name="imageResolution">Image resolution.</param>
        public static void Print(this ImageBox imageBox, Graphics graphics, RectF box, int imageResolution)
        {
            var state = graphics.Save();

            FillBox(imageBox.FilmBox, box, graphics);

            var boxCopy = box;
            if (imageBox.FilmBox.Trim == "YES")
            {
                boxCopy.Inflate(-BORDER, -BORDER);
            }

            if (imageBox.ImageSequence != null && imageBox.ImageSequence.Contains(DicomTag.PixelData))
            {
                Image bitmap = null;
                try
                {
                    var image = new DicomImage(imageBox.ImageSequence);
                    var frame = image.RenderImage().As<Image>();

                    bitmap = frame;

                    DrawBitmap(graphics, boxCopy, bitmap, imageResolution, imageBox.FilmBox.EmptyImageDensity);
                }
                finally
                {
                    if (bitmap != null)
                    {
                        bitmap.Dispose();
                    }
                }
            }

            graphics.Restore(state);
        }
コード例 #2
0
ファイル: RectFTest.cs プロジェクト: aerik/fo-dicom
 public void Assignment_ChangeInNewInstance_DoesNotAffectOldInstance()
 {
     var oldRect = new RectF(10f, 20f, 30f, 40f);
     var newRect = oldRect;
     newRect.Inflate(10f, 10f);
     Assert.Equal(10f, oldRect.X);
     Assert.Equal(20f, oldRect.Y);
     Assert.Equal(30f, oldRect.Width);
     Assert.Equal(40f, oldRect.Height);
 }
コード例 #3
0
ファイル: ImageBoxExtensions.cs プロジェクト: aerik/fo-dicom
 /// <summary>
 /// If requested, fill the box with black color.
 /// </summary>
 /// <param name="filmBox">Film box.</param>
 /// <param name="box">Rectangle.</param>
 /// <param name="graphics">Graphics.</param>
 private static void FillBox(FilmBox filmBox, RectF box, Graphics graphics)
 {
     if (filmBox.EmptyImageDensity == "BLACK")
     {
         RectF fillBox = box;
         if (filmBox.BorderDensity == "WHITE" && filmBox.Trim == "YES")
         {
             fillBox.Inflate(-BORDER, -BORDER);
         }
         using (var brush = new SolidBrush(Color.Black))
         {
             graphics.FillRectangle(brush, fillBox.X, fillBox.Y, fillBox.Width, fillBox.Height);
         }
     }
 }
コード例 #4
0
ファイル: RectFTest.cs プロジェクト: aerik/fo-dicom
 public void Inflate_Various_YieldCorrectNewRectangle(
     float x0,
     float y0,
     float w0,
     float h0,
     float inflateX,
     float inflateY,
     float x1,
     float y1,
     float w1,
     float h1)
 {
     var rect = new RectF(x0, y0, w0, h0);
     rect.Inflate(inflateX, inflateY);
     Assert.Equal(x1, rect.X);
     Assert.Equal(y1, rect.Y);
     Assert.Equal(w1, rect.Width);
     Assert.Equal(h1, rect.Height);
 }
コード例 #5
0
ファイル: ImageBoxExtensions.cs プロジェクト: aerik/fo-dicom
        /// <summary>
        /// Draw image bitmap in the specified rectangle.
        /// </summary>
        /// <param name="graphics">Graphics.</param>
        /// <param name="box">Rectangle in which to draw.</param>
        /// <param name="bitmap">Image to draw.</param>
        /// <param name="imageResolution">Image resolution.</param>
        /// <param name="emptyImageDensity">Empty image density.</param>
        private static void DrawBitmap(Graphics graphics, RectF box, Image bitmap, int imageResolution, string emptyImageDensity)
        {
            var imageWidthInInch = 100 * bitmap.Width / imageResolution;
            var imageHeightInInch = 100 * bitmap.Height / imageResolution;
            double factor = Math.Min(box.Height / imageHeightInInch, box.Width / imageWidthInInch);

            if (factor > 1)
            {
                var targetWidth = (int)(imageResolution * box.Width / 100);
                var targetHeight = (int)(imageResolution * box.Height / 100);


                using (var membmp = new Bitmap(targetWidth, targetHeight))
                {
                    membmp.SetResolution(imageResolution, imageResolution);

                    using (var memg = Graphics.FromImage(membmp))
                    {

                        memg.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bicubic;
                        memg.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

                        if (emptyImageDensity == "BLACK")
                        {
                            using (var brush = new SolidBrush(Color.Black))
                            {
                                memg.FillRectangle(brush, 0, 0, targetWidth, targetHeight);
                            }
                        }

                        factor = Math.Min(
                            targetHeight / (double)bitmap.Height,
                            targetWidth / (double)bitmap.Width);

                        var x = (float)((targetWidth - bitmap.Width * factor) / 2.0f);
                        var y = (float)((targetHeight - bitmap.Height * factor) / 2.0f);
                        var width = (float)(bitmap.Width * factor);
                        var height = (float)(bitmap.Height * factor);

                        memg.DrawImage(bitmap, x, y, width, height);
                    }
                    graphics.DrawImage(membmp, box.X, box.Y, box.Width, box.Height);
                }
            }
            else
            {
                var x = box.X + (float)(box.Width - imageWidthInInch * factor) / 2.0f;
                var y = box.Y + (float)(box.Height - imageHeightInInch * factor) / 2.0f;
                var width = (float)(imageWidthInInch * factor);
                var height = (float)(imageHeightInInch * factor);

                graphics.DrawImage(bitmap, x, y, width, height);
            }
        }
コード例 #6
0
ファイル: FilmBox.cs プロジェクト: aerik/fo-dicom
        /// <summary>
        /// Generate rectangles arranged in standard format.
        /// </summary>
        /// <param name="parts">Display format data.</param>
        /// <param name="marginBounds">Margin bounds.</param>
        /// <returns>Rectangles arranged in standard format.</returns>
        public static RectF[] PrintStandardFormat(string[] parts, RectF marginBounds)
        {
            if (parts.Length >= 3)
            {
                int columns = int.Parse(parts[1]);
                int rows = int.Parse(parts[2]);

                var boxWidth = marginBounds.Width / columns;
                var boxHeight = marginBounds.Height / rows;

                var boxes = new List<RectF>();
                for (int r = 0; r < rows; r++)
                {
                    for (int c = 0; c < columns; c++)
                    {

                        boxes.Add(
                            new RectF
                                {
                                    X = marginBounds.X + c * boxWidth,
                                    Y = marginBounds.Y + r * boxHeight,
                                    Width = boxWidth,
                                    Height = boxHeight
                                });
                    }
                }

                return boxes.ToArray();
            }

            return null;
        }
コード例 #7
0
ファイル: FilmBox.cs プロジェクト: aerik/fo-dicom
        /// <summary>
        /// Generate rectangles arranged in row format.
        /// </summary>
        /// <param name="parts">Display format data.</param>
        /// <param name="marginBounds">Margin bounds.</param>
        /// <returns>Rectangles arranged in row format.</returns>
        public static RectF[] PrintRowFormat(string[] parts, RectF marginBounds)
        {
            if (parts.Length >= 2)
            {
                int rowsCount = parts.Length - 1;

                var boxHeight = marginBounds.Height / rowsCount;

                var boxes = new List<RectF>();

                for (int r = 0; r < rowsCount; r++)
                {
                    int colsCount = int.Parse(parts[r + 1]);

                    var boxWidth = marginBounds.Width / colsCount;

                    for (int c = 0; c < colsCount; c++)
                    {
                        boxes.Add(
                            new RectF
                                {
                                    X = marginBounds.X + c * boxWidth,
                                    Y = marginBounds.Y + r * boxHeight,
                                    Width = boxWidth,
                                    Height = boxHeight
                                });
                    }
                }
                return boxes.ToArray();
            }

            return null;
        }