首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >加载Dicom图像并显示它-使用ClearCanvas库

加载Dicom图像并显示它-使用ClearCanvas库
EN

Stack Overflow用户
提问于 2009-10-30 19:52:09
回答 2查看 8.1K关注 0票数 7

这是一个非常狭义和具体的问题,但我知道还有其他人在使用这个问题,所以我会一直祈祷,希望你们中的任何人都能把这个问题拍出来。

我正在开发一个WPF应用程序,其中一部分是Dicom查看器。我们希望使用第三方组件来处理Dicom的事情,而ClearCanvas是目前为止我们印象最好的一个。我们可以加载Dicom文件并获取属性,但在将图像数据放在image控件的Source属性上以显示它时遇到了问题。有谁有关于如何实现这一点的提示吗?

下面是我用来提取图像数据的代码:

代码语言:javascript
复制
var file = new DicomFile(dicomFilePath);
var patientName = file.DataSet.GetAttribute(DicomTags.PatientsName);
var imageData = file.DataSet.GetAttribute(DicomTags.PixelData);

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

代码语言:javascript
复制
var localSopDataSource = new LocalSopDataSource(new DicomFile(dicomFilePath));
var patientName = localSopDataSource.File.DataSet.GetAttribute(DicomTags.PatientsName);
var imageData = localSopDataSource.File.DataSet.GetAttribute(DicomTags.PixelData);
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-11-08 07:32:26

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

代码语言:javascript
复制
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;
    }
}

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

票数 7
EN

Stack Overflow用户

发布于 2013-07-15 02:08:58

好了,我已经成功地使用以下代码在Picturebox中显示了一个DICOM图像:

以下是我使用的程序集:

代码语言:javascript
复制
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文件,然后将其显示在picturebox中)

代码语言:javascript
复制
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();
        }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1649358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档