转载于:https://blog.csdn.net/qiangzi4646/article/details/80764262
参考上述链接:
static QMap<int, QString> imageType = {
{0xffd8ff, "jpg"},
{0xffd8ff, "jpeg"},
{0xffd8ff, "jpe"},
{0x89504e47, "png"},
{0x47494638, "gif"},
{0x49492a00, "tif"},
{0x424d, "bmp"},
{0x424d228c01, "bmp16"},
{0x424d824009, "bmp24"},
{0x424d8e1b03, "bmp256"}
};
QString getImageType(QString img)
{
QFile file(img);
if (!file.open(QIODevice::ReadOnly)) {
return "";
}
QDataStream in(&file);
quint32 magic;
in >> magic;
file.close();
if (imageType.contains(magic)) {
return imageType[magic];
}
return "";
}
62c816d2-4963-49da-88c6-005284ce3ea5