当前位置: 网学 > 编程文档 > 其他类别 > 正文

BMP文件深入解析

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/19
下载{$ArticleTitle}原创论文样式
t tagBmpFile & F)
{
os << F.bfType << F.bfSize << F.bfReserved1 << F.bfReserved2 << F.bfOffBits;
return os;
}
}bmpFile;

//位图信息头
typedef struct tagBmpInfo
{
DWORD biSize;
DWORD biWidth;
DWORD biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
DWORD biXPelsPerMeter;
DWORD biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
const struct tagBmpInfo & operator = (const struct tagBmpInfo & I)
{
if (&I != this)
{
biSize = I.biSize;
biWidth = I.biWidth;
biHeight = I.biHeight;
biPlanes = I.biPlanes;
biBitCount = I.biBitCount;
biCompression = I.biCompression;
biSizeImage = I.biSizeImage;
biXPelsPerMeter = I.biXPelsPerMeter;
biYPelsPerMeter = I.biYPelsPerMeter;
biClrUsed = I.biClrUsed;
biClrImportant = I.biClrImportant;
}
return *this;
}

friend std::istream & operator>>(std::istream & is,struct tagBmpInfo & F)
{
is >> F.biSize
>> F.biWidth
>> F.biHeight
>> F.biPlanes
>> F.biBitCount
>> F.biCompression
>> F.biSizeImage
>> F.biXPelsPerMeter
>> F.biYPelsPerMeter
>> F.biClrUsed
>> F.biClrImportant;
return is;
}

friend std::ostream & operator<<(std::ostream & os,const struct tagBmpInfo & F)
{
os << F.biSize
<< F.biWidth
<< F.biHeight
<< F.biPlanes
<< F.biBitCount
<< F.biCompression
<< F.biSizeImage
<< F.biXPelsPerMeter
<< F.biYPelsPerMeter
<< F.biClrUsed
<< F.biClrImportant;
return os;
}
}bmpInfo;


//调色板
typedef struct tagRGBQuad
{
BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
const struct tagRGBQuad & operator = (const struct tagRGBQuad & Q)
{
if (&Q != this)
{
rgbBlue = Q.rgbBlue;
rgbGreen = Q.rgbGreen;
rgbRed = Q.rgbRed;
rgbReserved = Q.rgbReserved;
}
return *this;
}

friend std::istream & operator>>(std::istream & is,struct tagRGBQuad & F)
{
is >> F.rgbBlue
>> F.rgbGreen
>> F.rgbRed
>> F.rgbReserved;
return is;
}

friend std::ostream & operator<<(std::ostream & os,const struct tagRGBQuad & F)
{
os << F.rgbBlue
<< F.rgbGreen
<< F.rgbRed
<< F.rgbReserved;
return os;
}
} RGBQuad;

//位图结构
typedef struct _CBmp
{
std::string filePass;
bmpFile bmpFileH;
bmpInfo bmpInfoH;
DWORD storeWidth;
bitField bmpBitField;
RGBQuad * bmpRGB;
BYTE * bmpData;

BYTE & grasp(DWORD i, DWORD j)
{
return bmpData[(i)*storeWidth+(j)];
}
}CBmp;

bool openBmp(CBmp & inBmp,const std::string fpass)
{
FILE * inbmpF;
WORD colorCount;

if ((inbmpF=fopen(fpass.c_str(),"rb"))==NULL)
return false;
else
{
fread(&inBmp.bmpFileH.bfType,2,1,inbmpF);
fread(&inBmp.bmpFileH.bfSize,4,1,inbmpF);
fread(&inBmp.bmpFileH.bfReserved1,2,1,inbmpF);
fread(&inBmp.bmpFileH.bfReserved2,2,1,inbmpF);
fread(&inBmp.bmpFileH.bfOffBits,4,1,inbmpF);

//fread(&bmpFileH,14,1,inbmpF);
fread(&inBmp.bmpInfoH,40,1,inbmpF);
if (0<inBmp.bmpInfoH.biBitCount&&inBmp.bmpInfoH.biBitCount<=8)
colorCount=(WORD)(pow(2,inBmp.bmpInfoH.biBitCount));
else
colorCo
  • 上一篇资讯: 注册表的基础知识
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号