7

这是一个非常狭窄和具体的问题,但我知道还有其他人在使用它,所以我会保持双手交叉,并希望你们中的任何人都能提出这个问题。

我正在开发一个 WPF 应用程序,其中一部分是 Dicom 查看器。我们想使用一个 3rd 方组件来处理 Dicom 的东西,而 ClearCanvas 是迄今为止我们印象最好的一个。我们能够加载 Dicom 文件并获取属性,但是我们在将图像数据放在 Image 控件的 Source 属性上以显示它时遇到了问题。任何人都提示如何做到这一点?

这是我用于提取图像数据的代码:

var file = new DicomFile(dicomFilePath);
var patientName = file.DataSet.GetAttribute(DicomTags.PatientsName);
var imageData = file.DataSet.GetAttribute(DicomTags.PixelData);

也尝试过使用 ImageViewer 库,但它仍然是相同的数据..

var localSopDataSource = new LocalSopDataSource(new DicomFile(dicomFilePath));
var patientName = localSopDataSource.File.DataSet.GetAttribute(DicomTags.PatientsName);
var imageData = localSopDataSource.File.DataSet.GetAttribute(DicomTags.PixelData);
4

2 回答 2

7

好的,我想通了.. 可能还有更多方法可以实现这一点,但这就是我所做的。现在我有一个 Wpf Image 绑定到提供位图数据的属性。以下是用于提供位图数据的属性。

public BitmapSource CurrentFrameData
{
    get
    {
        LocalSopDataSource _dicomDataSource = 
            new LocalSopDataSource(_dicomFilePath);
        var imageSop = new ImageSop(_dicomDataSource);

        IPresentationImage presentationImage = 
            PresentationImageFactory.Create(imageSop.Frames[CurrentFrame]);

        int width = imageSop.Frames[CurrentFrame].Columns;
        int height = imageSop.Frames[CurrentFrame].Rows;

        Bitmap bmp = presentationImage.DrawToBitmap(width, height);
        BitmapSource output = Imaging.CreateBitmapSourceFromHBitmap(
          bmp.GetHbitmap(),
          IntPtr.Zero,
          Int32Rect.Empty,
          BitmapSizeOptions.FromWidthAndHeight(width, height));

          return output;
    }
}

请注意,这是一个非常直接的解决方案。例如,一个人可能想要做一些事情,比如预加载图片等,以避免在滚动多帧图像时负载过重。但是对于“如何显示图像”问题 - 这应该回答它..

于 2009-11-07T23:32:25.577 回答
0

好的,我已经设法使用以下代码在 Picturebox 中显示 DICOM 图像:

这是我使用的程序集:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ClearCanvas.Common;
using ClearCanvas.Dicom;
using System.Windows.Media.Imaging;
using ClearCanvas.ImageViewer;
using ClearCanvas.ImageViewer.StudyManagement;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows;
using System.IO;

我还必须将这些 dll 复制到 bin/debug 中:

BilinearInterpolation.dll(这个我不能将它作为汇编引用,所以我只是将它复制到 bin/degug 文件夹中)

WindowsBase.dll(这个我可以将它作为一个程序集引用)

代码(我的项目中有一个按钮,可以让您选择 dcm 文件,然后将其显示在图片框中)

Private void button2_Click(object sender, EventArgs e)
    {
        OpenFileDialog ofd = new OpenFileDialog();
        ofd.Filter = "DICOM Files(*.*)|*.*";
        if (ofd.ShowDialog() == DialogResult.OK)
        {
            if (ofd.FileName.Length > 0)
            {

                var imagen = new DicomFile(ofd.FileName); 

                LocalSopDataSource DatosImagen = new LocalSopDataSource(ofd.FileName); 

        ImageSop imageSop = new ImageSop(DatosImagen);

        IPresentationImage imagen_a_mostrar = PresentationImageFactory.Create(imageSop.Frames[1]); 

        int width = imageSop.Frames[1].Columns; 

        int height = imageSop.Frames[1].Rows; 

        Bitmap bmp = imagen_a_mostrar.DrawToBitmap(width, height); 

        PictureBox1.Image = bmp; 



            imageOpened = true;

            }
            ofd.Dispose();
        }
    }
于 2013-07-14T18:08:58.057 回答