在BMP位图里添加标尺的有关问题(有兴趣的朋友来看看)

jixuchen 2005-08-10 05:06:44
BOOL BitmapFile(CString strFileName,CBitmap& bmp)
{
BITMAPFILEHEADER bmfh;//BMP文件头变量

BITMAPINFOHEADER bmih;//BMP文件信息变量

int nWidth = bmih.biWidth;

int nByteWidth = nWidth*3;

int nHeight = bmih.biHeight;

int nLen = nByteWidth*nHeight;

RGBTRIPLE *rgb = new RGBTRIPLE[bmih.biWidth * bmih.biHeight];//24位真彩色数据格式

BYTE *pd1=new BYTE[nLen + sizeof(BITMAPINFOHEADER) + sizeof(BITMAPFILEHEADER)];

BYTE *pd2=new BYTE[nLen + sizeof(BITMAPINFOHEADER) + sizeof(BITMAPFILEHEADER)];

CFile file1, file2;

file1.Open(strFileName, CFile::modeCreate);

file2.Open(strFileName, CFile::modeRead);

CFileException e;//出错处理

file2.SeekToEnd();

file2.Read(pd2, 54);

file1.SeekToBegin();
//pd2[1] = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+bmih.biWidth*bmih.biHeight*3;
//pd2[17] = nWidth + rgb->rgbtBlue;
//pd2[21] = nHeight + rgb->rgbtBlue;
bmih.biWidth=nWidth + rgb->rgbtBlue + 5;
bmih.biHeight=nHeight + rgb->rgbtBlue + 5;
bmfh.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+bmih.biWidth*bmih.biHeight*3;
file1.Write(pd1, 54);
for(int i=0;i <= nHeight;i++)
{
file2.Seek(54 + i * nByteWidth , CFile::begin);
file2.Read(pd2, nWidth * 3);
file1.SeekToEnd();
file1.Write(pd2,nWidth * 3);
file1.SeekToEnd();
if (i % 5 == 0)
{
*pd1 = rgb->rgbtBlue + 5;
}
else
{
*pd1 = rgb->rgbtBlue;
}
file1.Write(pd1,rgb->rgbtBlue + 5);
}

delete rgb;
delete pd1;
delete pd2;
file1.Close();
file2.Close();
return TRUE;
}

该函数提供了修改位图格式的功能,但有点问题,希望大虾能帮助改下;

不甚感激。。。

QQ:40604399
jack_xc@126.com
...全文
58 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

19,469

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧