在BMP位图里添加标尺的有关问题(有兴趣的朋友来看看)
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