C++ウィジェット:bmpピクチャ解析
3360 ワード
コンパイラ:visual studio 2019
作業ディレクトリにbmp形式の画像を置く必要があります.ここでは「image.bmp」と名付けて、任意に名前を付けることができます.
プログラムが簡単で、出力もはっきりしているので、実行すればいいです.
参照先:
https://blog.csdn.net/heybeaman/article/details/81908118
https://blog.csdn.net/u013509299/article/details/41660935ああ、私のコードはこのブログを参考にして、いくつかの変更をしました.
https://blog.csdn.net/luhu124541/article/details/82024835
作業ディレクトリにbmp形式の画像を置く必要があります.ここでは「image.bmp」と名付けて、任意に名前を付けることができます.
プログラムが簡単で、出力もはっきりしているので、実行すればいいです.
#include
#include
#include
#include
using namespace std;
int main(void)
{
errno_t err;
FILE* fp;
if (err = fopen_s(&fp, "image.bmp", "r"))
{
cout << "fail to open." << endl;
exit(-1);
}
BITMAPFILEHEADER bmpFileHeader;
fread(&bmpFileHeader, sizeof(BITMAPFILEHEADER), 1, fp);
BITMAPINFOHEADER bmpInfoHeader;
fread(&bmpInfoHeader, sizeof(BITMAPINFOHEADER), 1, fp);
cout << setiosflags(ios::left); //
//B,M ASCII 16 0x42,0x4d,0x4d42 19778, bfType 19778 , bmp
cout << setw(40) << "bfType:" << setw(20) << bmpFileHeader.bfType << endl;
cout << setw(40) << " :" << bmpFileHeader.bfSize << "Byte, " << bmpFileHeader.bfSize / 1024 << "kB" << endl;
cout << setw(40) << " :" << bmpFileHeader.bfOffBits << "Byte" << endl;
cout << setw(40) << "bmp :" << bmpInfoHeader.biSize << "Byte" << endl;
cout << setw(40) << " :" << bmpInfoHeader.biWidth << "pixel" << endl;
cout << setw(40) << " :" << bmpInfoHeader.biHeight << "pixel" << endl;
cout << setw(40) << " :" << bmpInfoHeader.biBitCount << "bit, " << bmpInfoHeader.biBitCount / 8 << "Byte" << endl;
switch (bmpInfoHeader.biCompression)
{
case 0:
cout << setw(40) << " :" << " " << endl;
break;
case 1:
cout << setw(40) << " :" << "8 , 8 " << endl;
break;
case 2:
cout << setw(40) << " :" << "4 , 4 " << endl;
break;
case 3:
cout << setw(40) << " :" << " , 16/32 " << endl;
break;
case 4:
cout << setw(40) << " :" << " JPEG ( )" << endl;
break;
case 5:
cout << setw(40) << " :" << " PNG ( )" << endl;
break;
}
switch (bmpInfoHeader.biClrUsed)
{
case 0:
cout << " , " << endl;
break;
default:
cout << setw(40) << " :" << bmpInfoHeader.biClrUsed << endl;
break;
}
switch (bmpInfoHeader.biClrImportant)
{
case 0:
cout << setw(40) << " :" << " " << endl;
break;
default:
cout << setw(40) << " :" << bmpInfoHeader.biClrImportant << endl;
break;
}
fclose(fp);
return 0;
}
参照先:
https://blog.csdn.net/heybeaman/article/details/81908118
https://blog.csdn.net/u013509299/article/details/41660935ああ、私のコードはこのブログを参考にして、いくつかの変更をしました.
https://blog.csdn.net/luhu124541/article/details/82024835