Writing BMP image in pure c/c++ without other libraries(在没有其他库的情况下用纯 c/c++ 编写 BMP 图像)
问题描述
在我的算法中,我需要创建一个信息输出.我需要将一个布尔矩阵写入 bmp 文件.它必须是单色图像,如果此类元素上的矩阵为真,则像素为白色.主要问题是 bmp 标头以及如何编写它.
In my algorithm, I need to create an information output. I need to write a boolean matrix into a bmp file. It must be a monocromic image, where pixels are white if the matrix on such element is true. Main problem is the bmp header and how to write this.
推荐答案
无需使用任何其他库,您可以查看 BMP 文件格式.我过去已经实现过,不需要太多工作就可以完成.
Without the use of any other library you can look at the BMP file format. I've implemented it in the past and it can be done without too much work.
位图文件结构
每个位图文件包含一个位图文件头,一个位图信息头,一种颜色表,以及一个字节数组定义位图位.该文件有以下形式:
Each bitmap file contains a bitmap-file header, a bitmap-information header, a color table, and an array of bytes that defines the bitmap bits. The file has the following form:
位图文件头 bmfh;
BITMAPINFOHEADER bmih;
RGBQUAD aColors[];
BYTE aBitmapBits[];
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih;
RGBQUAD aColors[];
BYTE aBitmapBits[];
...查看文件格式以获取更多详细信息
... see the file format for more details
这篇关于在没有其他库的情况下用纯 c/c++ 编写 BMP 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在没有其他库的情况下用纯 c/c++ 编写 BMP 图像
基础教程推荐
- 初始化列表*参数*评估顺序 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
