C++ bmp位图读取

本文介绍如何使用C++读取24位和32位BMP图片格式的颜色矩阵,并展示读取过程。BMP文件分为header、infoheader、optional palette(仅在某些情况下存在)和image data四部分。对于24位BMP,由于每行像素需要与4字节对齐,因此需要计算并填充额外字节。32位BMP由于天然与4字节对齐,读取更为简单。文章提供了一种利用DirectX打印像素的方法,但未给出完整代码,后续将补充矩阵打印与详细注释。
摘要由CSDN通过智能技术生成

如何用C++读取  bmp图片格式颜色矩阵 以及显示

首先   简单解释一下bmp文件格式                在 http://paulbourke.net/dataformats/bmp/  有官方详细解释

                                                                       


bmp 格式文件  分为四个部分    

header                   文件格式,大小

infoheader            图像的高,宽,位数

optional palette    可选调色板:使用索引来表示图像是的 索引与颜色的映射 并非一定包含

image data            图像像素信息的数据


其中24位bmp文件不使用索引 所以不需要optional palette 部分

header C结构体
typedef struct {
   unsigned short int type;                 /* Magic identifier   文件格式*/
   unsigned int size;                       /* File size in bytes 文件大小*/
   unsigned short int reserved1, reserved2; /* 保留区 默认设置为0          */
   unsigned int offset;                     /* Offset to image data, bytes文件头到图像数据信息便宜字节 */
} HEADER;

infoheader 结构体
typedef struct {
   unsigned int size;               /* Header size in bytes   infoheader文件部分size大小   */
   int width,height;                /* Width and height of image  图像宽,高   */
   unsigned short int planes;       /* Number of colour planes    位面数 总为1 */
   unsigned short int bits;         /* Bits per pixel             像素位深     */
   unsigned int compression;        /* Compression type     	  压缩类型     */
   unsigned int imagesize;          /* Image size in bytes    图像大小(字节)    */
   int xresolution,yresolution;     /* Pixe
  • 3
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值