用于编写BMP图像的bmpinfoheader

时间:2014-10-06 03:41:36

标签: matlab image-processing bmp

我正在尝试编写用于将文件写入BMP文件的MATLAB代码。

我知道我可以使用imwrite()功能。但我的任务是避免它。

我需要有关如何编写bmpinfoheader的信息?到目前为止,我只知道它是14位数组。

1 个答案:

答案 0 :(得分:2)

8位BMP

%---- BitMapfileHeader
fwrite(fid, hex2dec('42'), 'uchar');     % 'B' in ASCII code
fwrite(fid, hex2dec('4D'), 'uchar');     % 'M' in ASCII code
fwrite(fid, 54 + sz + 256 * 4, 'ulong'); % file size
fwrite(fid, 0, 'ushort');                % always 0
fwrite(fid, 0, 'ushort');                % always 0
fwrite(fid, 54 + 256 * 4, 'ulong');      % offset
%---- BitMapInfoHeader
fwrite(fid, 40, 'ulong');                % BitMapInfoHeader size
fwrite(fid, width, 'long');              % image width
fwrite(fid, height, 'long');            % image height (negative; positive=upside-down)
fwrite(fid, 1, 'ushort');                % always 1
fwrite(fid, 8, 'ushort');                % color bit
fwrite(fid, 0, 'ulong');                 % compression
fwrite(fid, sz, 'ulong');                % image size
fwrite(fid, dpm, 'long');                % horizontal resolution (dpm)
fwrite(fid, dpm, 'long');                % vertical resolution (dpm)
fwrite(fid, 256, 'ulong');               % # of color index
fwrite(fid, 0, 'ulong');                 % # of important color index

24位BMP

%---- BitMapfileHeader
fwrite(fid, hex2dec('42'), 'uchar');     % 'B' in ASCII code
fwrite(fid, hex2dec('4D'), 'uchar');     % 'M' in ASCII code
fwrite(fid, 54 + sz, 'ulong');           % file size
fwrite(fid, 0, 'ushort');                % always 0
fwrite(fid, 0, 'ushort');                % always 0
fwrite(fid, 54, 'ulong');                % offset
%---- BitMapInfoHeader
fwrite(fid, 40, 'ulong');                % BitMapInfoHeader size
fwrite(fid, width, 'long');              % image width
fwrite(fid, height, 'long');            % image height (negative; positive=upside-down)
fwrite(fid, 1, 'ushort');                % always 1
fwrite(fid, 24, 'ushort');               % color bit
fwrite(fid, 0, 'ulong');                 % compression
fwrite(fid, sz, 'ulong');                % image size
fwrite(fid, dpm, 'long');                % horizontal resolution (dpm)
fwrite(fid, dpm, 'long');                % vertical resolution (dpm)
fwrite(fid, 0, 'ulong');                 % # of color index
fwrite(fid, 0, 'ulong');                 % # of important color index

来源 - http://www.h6.dion.ne.jp/~fff/old/technique/matlab/matlab_V.html

或者看看这里的结构

http://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx http://www.herdsoft.com/ti/davincie/davp3xo2.htm