gdmcgdcmPinvoke有一个例外。为什么?
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";
}
}
}发布于 2010-09-09 02:37:46
我建议不要使用任何DICOM Reader来完成此任务,因为这将大大增加该过程的开销。在这种情况下使用完整DICOM库的唯一原因是,如果要验证文件的所有元素,并确保文件实际上是DICOM文件。
我的第一个建议是简单地依靠文件扩展名(通常是".DCM")来标识DICOM文件。然后,如果文件的格式不正确,则在用户尝试打开文件时通知用户。据我所知,没有其他文件格式使用".DCM“扩展名。
如果这是不能接受的(比如你的文件没有扩展名),我只会为你的特定用例做最低限度的验证。DICOM文件将始终包含128字节的前导,后跟字母"DICM“(不带引号)。您可以用您想要的任何内容填充前同步码,但字节129-132必须始终包含"DICM“。这是最小的文件验证,我建议如下:
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";
}https://stackoverflow.com/questions/3650579
复制相似问题