在没有其他库的情况下用纯 c/c++ 编写 BMP 图像 [英] Writing BMP image in pure c/c++ without other libraries

查看:32
本文介绍了在没有其他库的情况下用纯 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 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆