首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C# gdcm加载dicom

C# gdcm加载dicom
EN

Stack Overflow用户
提问于 2010-09-06 18:06:19
回答 1查看 2.6K关注 0票数 0

gdmcgdcmPinvoke有一个例外。为什么?

代码语言:javascript
复制
foreach (string el in files_in_folder)
{
    try
    {
        gdcm.ImageReader reader = new gdcm.ImageReader();
        reader.SetFileName(el);

        if (reader.Read())
        {
            textBox1.Text="Image loaded"; 

            reader.GetImage() ;

            ListViewItem str = new ListViewItem(el);

            str.Text = el;

            listView1.Items.Add(str.Text);
        }
        else
        {
            textBox1.Text = "This is not a DICOM file";
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-09-09 02:37:46

我建议不要使用任何DICOM Reader来完成此任务,因为这将大大增加该过程的开销。在这种情况下使用完整DICOM库的唯一原因是,如果要验证文件的所有元素,并确保文件实际上是DICOM文件。

我的第一个建议是简单地依靠文件扩展名(通常是".DCM")来标识DICOM文件。然后,如果文件的格式不正确,则在用户尝试打开文件时通知用户。据我所知,没有其他文件格式使用".DCM“扩展名。

如果这是不能接受的(比如你的文件没有扩展名),我只会为你的特定用例做最低限度的验证。DICOM文件将始终包含128字节的前导,后跟字母"DICM“(不带引号)。您可以用您想要的任何内容填充前同步码,但字节129-132必须始终包含"DICM“。这是最小的文件验证,我建议如下:

代码语言:javascript
复制
foreach (string el in files_in_folder)
{
    bool isDicomFile = false;
    using (FileStream fs = new FileStream(el, FileMode.Open))
    {
        byte[] b = new byte[4];
        fs.Read(b, 128, b.Length);
        ASCIIEncoding enc = new ASCIIEncoding();
        string verification = enc.GetString(b);
        if (verification == "DICM")
            isDicomFile = true;
        fs.Close();
    }
    if (isDicomFile)
        listView1.Items.Add(new ListViewItem(el));
    // I would discourage the use of this else, since even
    // if only one file in the list fails, the TextBox.Text
    // will still be set to "This is not a DICOM file".
    else
        textBox1.Text = "This is not a DICOM file";
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3650579

复制
相关文章

相似问题

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