创建位图图像时遇到问题;fileheader/infoheader错误
Having trouble creating a bitmap image; fileheader/infoheader is wrong
我正试图根据高功率相机(Allied Vision Technologies Prosilica GT2750)拍摄的图像创建一个24位图图像。到目前为止,我有以下内容:(注意VmbUInt32被定义为"typedef unsigned __int32 VmbUInt32_t;"而VmbUchar_t只是一个无符号字符)
VmbUint32_t imageSize = 0;
pFrame->GetImageSize(imageSize); //imageSize = 6054400
VmbUint32_t imageWidth = 0;
pFrame->GetWidth(imageWidth); //imageWidth = 2752
VmbUint32_t imageHeight = 0;
pFrame->GetHeight(imageHeight); //imageHeight = 2200
//////////////////////////////////////////////////////////////////////////
////////// Set Bitmap Settings ////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//file header
BITMAPFILEHEADER* bf = new BITMAPFILEHEADER;
bf->bfType = 0x4d42;
bf->bfSize = imageSize + 40 + 14; //image size + infoheader size + fileheader size
bf->bfOffBits = 54;
//info header
BITMAPINFOHEADER* bi = new BITMAPINFOHEADER;
bi->biSize = 40;
bi->biWidth = imageWidth;
bi->biHeight = imageHeight;
bi->biPlanes = 1;
bi->biBitCount = 24;
bi->biCompression = 0;
bi->biSizeImage = imageSize;
bi->biXPelsPerMeter = 2835;
bi->biYPelsPerMeter = 2835;
bi->biClrUsed = 0;
bi->biClrImportant = 0;
//image data
VmbUchar_t* imageData = new VmbUchar_t[imageSize];
pFrame->GetImage(imageData);
//////////////////////////////////////////////////////////////////////////
////////// Output File to .bmp ////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
std::ofstream outFile;
outFile.open("test.bmp", std::ios::binary|std::ios::out);
outFile.write(reinterpret_cast<char *>(bf), sizeof(BITMAPFILEHEADER));
outFile.write(reinterpret_cast<char *>(bi), sizeof(BITMAPINFOHEADER));
outFile.write(reinterpret_cast<char *>(imageData), imageSize);
outFile.close();
基本上,数据被正确地写入test.bmp,但test.bmp在标准图像查看器中仍然无法处理。当我在十六进制编辑器中查看test.bmp时,似乎一切正常。我知道imageData工作正常,因为当我把灯调到最大值时,imageData只是一堆FF(又名白色),当我关灯时,imageData的每个像素都是00、01或02。(又名黑色或接近黑色)。因此,文件的imageData部分被正确写入。我可以使用他们提供的软件来查看相机的图像,这样我就知道相机工作得很好(这也是我用来确保光线足够亮,可以是白色屏幕,足够暗,可以是黑色屏幕)。然而,文件头或信息头(或两者)肯定有问题,我似乎无法弄清楚它是什么
这是文件头和信息头的十六进制数据:
42 4D 36 62 5C 00 CD CD CD CD 36 00 00 00 28 00 00 00 C0
0D 0A 00 00 98 08 00 00 01 00 18 00 00 00 00 00 00 62 5C
00 13 0B 00 00 13 0B 00 00 00 00 00 00 00 00 00 00
每次运行的imageSize、imageWidth和imageHeight都相同(分别为6054400、2752、2200),获取它们的函数来自相机的API。这些函数工作正常,只返回整数(至少从我在autos中看到的情况来看)。
其他信息:我正在使用Visual Studio 2010。
TL;DR:我的文件头和/或信息头出了什么问题?
您的File头中可能缺少两个保留字段。
文件头:4字节BMP文件的大小(以字节为单位)预留2个字节;实际值取决于创建图像的应用程序预留2个字节;实际值取决于创建图像的应用程序4字节——可以找到位图图像数据(像素阵列)的字节的偏移量,即起始地址。
- Mac os x app bundle 在下载并运行时崩溃,但在终端或更改 Info.plist 时运行良好
- IS类型INFO自动更新了以前调用Destructor
- 提升信息解析器在读取/写入 INFO 格式文件时删除所有注释
- 我如何允许向量传递到info(),capture(),warn()等,同时避免非法扩展std名称空间
- std :: getline(输入,d.info)不起作用
- 什么是log(info)和日志(错误)进行
- 访问冲突错误在 (而 (info[x] != ))
- Electron-无日志消息由C++文件中的log(INFO)打印
- 如何在 WP 8.1 或 WP 8 中的本机C++中使用命名空间 - Microsoft.Phone.Info
- 使用 #define 和 clang 为 info.plist 创建版本号变体
- 使用 sysctl() 的 OSX 上的 info CPU
- 波特迪奥和阿尔萨:"Cannot obtain info for CTL elem"
- 我的输出中的D3D11 INFO行是什么意思
- 创建位图图像时遇到问题;fileheader/infoheader错误
- "类形状"没有名为"info"的成员,但添加一个也不起作用