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 图像
基础教程推荐
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 常量变量在标题中不起作用 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
