問題描述
在我的算法中,我需要創建一個信息輸出.我需要將一個布爾矩陣寫入 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 圖像的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!