判断依据:根据DICOM前缀,长度为4个字节的字符串是否等于“DICM”来判断该文件是否属于DICOM文件
/判断目标文件是否为DICOM文件/
bool IsDicomFile(QString path)
{
// 判断是否为dicom文件
char buffer[0x85];
std::string s = path.toStdString();
std::ifstream in(path.toStdString().c_str());
in.getline(buffer, 0x85);
if (!((buffer[0x80] == 0x44) && (buffer[0x81] == 0x49) &&
(buffer[0x82] == 0x43) && (buffer[0x83] == 0x4D)))
{
std::cout << path.toStdString() << std::endl;
std::cout << “It’s not a DICOM File!” << std::endl;
return false;
}
return true;
}