欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

图片格式的识别

程序员文章站 2024-02-18 19:52:34
...
/识别图片格式

QString getImgFmt(constQString&imagePath)
{
QFile imageFile(imagePath);
if(!imageFile.open(QIODevice::ReadWrite)){
return QString();
}
QByteArrayba =imageFile.readAll();

QString imgFmt =QString();
if(0x424D== ((ba[0]& 0xff)<< 8| (ba[1]& 0xff))){
imgFmt.append("bmp");
}
else if(0x8950== ((ba[0]& 0xff)<< 8| (ba[1]& 0xff))){
imgFmt.append("png");
}
else if(0xFFD8== ((ba[0]/&0xff)<< 8| (ba[1]& 0xff))){
imgFmt.append("jpg");
}

return imgFmt;
}


int main()
{
QString path_0("D:\\workspace\\aaa.bmp");
int bmpDepth =getBmpBitDepth(path_0);

QString path_1("D:\\workspace\\tray.png");
int pngDepth =getPngBitDepth(path_1);

QString path_2("D:\\workspace\\1111.png");
int jpegDepth =getJpegBitDepth(path_2);

QString fmt =getImgFmt(path_2);
printf("fmt=%s\n",fmt.toStdString().c_str());
}


相关标签: Qt 图片格式