示例#1
0
        /// <summary>
        /// Load image box for a specified <paramref name="filmBox"/> from a specified file.
        /// </summary>
        /// <param name="filmBox">Film box.</param>
        /// <param name="imageBoxFile">Name of the image box file.</param>
        /// <returns>Image box for a specified <paramref name="filmBox"/> from a file named <paramref name="imageBoxFile"/>.</returns>
        public static ImageBox Load(FilmBox filmBox, string imageBoxFile)
        {
            var file = DicomFile.Open(imageBoxFile);

            var imageBox = new ImageBox(
                filmBox,
                file.FileMetaInfo.MediaStorageSOPClassUID,
                file.FileMetaInfo.MediaStorageSOPInstanceUID);

            file.Dataset.CopyTo(imageBox);
            return(imageBox);
        }
        /// <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 DoPrint(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 iimage = image.RenderImage();

#if !NET_CORE
                    if (iimage is WPFImage)
                    {
                        var frame = iimage.AsWriteableBitmap().AsBitmap();
                        bitmap = frame;
                    }
                    else
#endif
                    {
                        var frame = iimage.As <Image>();
                        bitmap = frame;
                    }

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

            graphics.Restore(state);
        }
示例#3
0
        /// <summary>
        /// Load a film box for a specific session from a specific folder.
        /// </summary>
        /// <param name="filmSession">Film session.</param>
        /// <param name="filmBoxFolder">Folder in which film box is stored.</param>
        /// <returns>Film box for the specified <paramref name="filmSession"/> located in the <paramref name="filmBoxFolder"/>.</returns>
        public static FilmBox Load(FilmSession filmSession, string filmBoxFolder)
        {
            var filmBoxFile = string.Format(@"{0}\FilmBox.dcm", filmBoxFolder);

            var file = DicomFile.Open(filmBoxFile);

            var filmBox = new FilmBox(filmSession, file.FileMetaInfo.MediaStorageSOPInstanceUID, file.Dataset);

            var imagesFolder = IOManager.CreateDirectoryReference(string.Format(@"{0}\Images", filmBoxFolder));

            foreach (var image in imagesFolder.EnumerateFileNames("*.dcm"))
            {
                var imageBox = ImageBox.Load(filmBox, image);

                filmBox.BasicImageBoxes.Add(imageBox);
            }
            return(filmBox);
        }
示例#4
0
 /// <summary>
 /// Construct new ImageBox cloned from another imagebox
 /// </summary>
 /// <param name="imageBox">The source ImageBox instance to clone</param>
 /// <param name="filmBox">The film box.</param>
 private ImageBox(ImageBox imageBox, FilmBox filmBox)
     : this(filmBox, imageBox.SOPClassUID, imageBox.SOPInstanceUID)
 {
     imageBox.CopyTo(this);
     InternalTransferSyntax = imageBox.InternalTransferSyntax;
 }
示例#5
0
        public static ImageBox Load(FilmBox filmBox, string imageBoxFile)
        {
            var file = DicomFile.Open(imageBoxFile);

            var imageBox = new ImageBox(filmBox, file.FileMetaInfo.MediaStorageSOPClassUID, file.FileMetaInfo.MediaStorageSOPInstanceUID);

            file.Dataset.CopyTo(imageBox);
            return imageBox;
        }
示例#6
0
 /// <summary>
 /// Construct new ImageBox cloned from another imagebox
 /// </summary>
 /// <param name="imageBox">The source ImageBox instance to clone</param>
 private ImageBox(ImageBox imageBox, FilmBox filmBox)
     : this(filmBox, imageBox.SOPClassUID, imageBox.SOPInstanceUID)
 {
     imageBox.CopyTo(this);
     this.InternalTransferSyntax = imageBox.InternalTransferSyntax;
 }
示例#7
0
文件: FilmBox.cs 项目: aerik/fo-dicom
        /// <summary>
        /// Create image box from DICOM data.
        /// </summary>
        private void CreateImageBox()
        {
            DicomUID classUid = DicomUID.BasicGrayscaleImageBoxSOPClass;

            if (_filmSession.IsColor)
            {
                classUid = DicomUID.BasicColorImageBoxSOPClass;
            }

            DicomUID sopInstance = new DicomUID(
                string.Format("{0}.{1}", SOPInstanceUID.UID, BasicImageBoxes.Count + 1),
                SOPInstanceUID.Name,
                SOPInstanceUID.Type);

            var imageBox = new ImageBox(this, classUid, sopInstance);
            imageBox.ImageBoxPosition = (ushort)(BasicImageBoxes.Count + 1);

            BasicImageBoxes.Add(imageBox);

            var item = new DicomDataset();
            item.Add(DicomTag.ReferencedSOPClassUID, classUid);
            item.Add(DicomTag.ReferencedSOPInstanceUID, sopInstance);

            var seq = Get<DicomSequence>(DicomTag.ReferencedImageBoxSequence);
            seq.Items.Add(item);
        }
示例#8
0
文件: PrintJob.cs 项目: GMZ/fo-dicom
        public void DrawImageBox(ImageBox imgBox, Graphics graphics, RectangleF box, int imageResolution)
        {
            var imageSequence = imgBox.ImageSequence;
            var state = graphics.Save();

            FillBox(box, graphics);

            var imageBox = box;
            if (_currentFilmBox.Trim == "YES")
            {
                imageBox.Inflate(-Hundredths, -Hundredths);
            }

            if (imageSequence != null && imageSequence.Contains(DicomTag.PixelData))
            {
                Image bitmap = null;
                try
                {
                    var image = new DicomImage(imageSequence);
                    var frame = image.RenderImage();

                    bitmap = frame;
                    if (imgBox.Polarity == "REVERSE")
                    {
                        bitmap = Transform((Bitmap)bitmap);
                    }

                    DrawBitmap(graphics, box, bitmap, imageResolution);
                }
                finally
                {
                    if (bitmap != null)
                    {
                        bitmap.Dispose();
                    }
                }
            }

            graphics.Restore(state);
        }