void CExample10View::OnSave555BiBitfields()
{
// TODO: Add your command handler code here
if(lpBmpDataBuf==NULL)
{
MessageBox("当前没有打开的位图");
return;
}
BYTE r,g,b;
LPBYTE lpDest,lpSrc;
int i,j;
int nheapSize;
CFileDialog filesavebox(FALSE,"bmp","BI_BITFIELDS.bmp",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"files(*.bmp)|*.bmp|",NULL);
CFile file;
CString strPathname;
if(m_bmi.biBitCount!=24)
{
MessageBox("当前打开的位图不是24位位图");
return;
}
memcpy(&m_newbmf,&m_bmf,sizeof(BITMAPFILEHEADER));
memcpy(&m_newbmi,&m_bmi,sizeof(BITMAPINFOHEADER));
m_newbmi.biBitCount=16;
m_newbmi.biCompression=BI_BITFIELDS;//即3
m_newbmi.biSizeImage=WIDTHBYTES(m_newbmi.biWidth,m_newbmi.biBitCount)*m_newbmi.biHeight;
m_newbmf.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+sizeof(DWORD)*3
+WIDTHBYTES(m_newbmi.biWidth,m_newbmi.biBitCount)*m_newbmi.biHeight;
m_newbmf.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+sizeof(DWORD)*3;
nheapSize=sizeof(BITMAPINFOHEADER)+sizeof(DWORD)*3
+WIDTHBYTES(m_newbmi.biWidth,m_newbmi.biBitCount)*m_newbmi.biHeight;
if(lpnewBmpDataBuf!=NULL)
{
delete []lpnewBmpDataBuf;
lpnewBmpDataBuf=NULL;
}
lpnewBmpDataBuf=new BYTE[nheapSize];
memcpy(lpnewBmpDataBuf,&m_newbmi,sizeof(BITMAPINFOHEADER));
DWORD* lp=(DWORD*)(lpnewBmpDataBuf+sizeof(BITMAPINFOHEADER));
*lp++=0x00007c00;
*lp++=0x000003e0;
*lp =0x0000001f;
for(i=0;i>3);
}
}
if(filesavebox.DoModal()!=IDOK) return;
strPathname=filesavebox.GetPathName();
if(!file.Open(strPathname,CFile::modeCreate|CFile::modeWrite))
{
MessageBox("Can not Create File!");
return;
}
file.Write(&m_bmf,sizeof(BITMAPFILEHEADER));
file.Write(lpnewBmpDataBuf,nheapSize);
file.Close();
Invalidate(TRUE);
}
void CExample10View::OnSave565()
{
// TODO: Add your command handler code here
if(lpBmpDataBuf==NULL)
{
MessageBox("当前没有打开的位图");
return;
}
BYTE r,g,b;
LPBYTE lpDest,lpSrc;
int i,j;
int nheapSize;
CFileDialog filesavebox(FALSE,"bmp","565.bmp",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"files(*.bmp)|*.bmp|",NULL);
CFile file;
CString strPathname;
if(m_bmi.biBitCount!=24)
{
MessageBox("当前打开的位图不是24位位图");
return;
}
memcpy(&m_newbmf,&m_bmf,sizeof(BITMAPFILEHEADER));
memcpy(&m_newbmi,&m_bmi,sizeof(BITMAPINFOHEADER));
m_newbmi.biBitCount=16;
m_newbmi.biCompression=BI_BITFIELDS;//即3
m_newbmi.biSizeImage=WIDTHBYTES(m_newbmi.biWidth,m_newbmi.biBitCount)*m_newbmi.biHeight;
m_newbmf.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+sizeof(DWORD)*3
+WIDTHBYTES(m_newbmi.biWidth,m_newbmi.biBitCount)*m_newbmi.biHeight;
m_newbmf.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+sizeof(DWORD)*3;
nheapSize=sizeof(BITMAPINFOHEADER)+sizeof(DWORD)*3
+WIDTHBYTES(m_newbmi.biWidth,m_newbmi.biBitCount)*m_newbmi.biHeight;
if(lpnewBmpDataBuf!=NULL)
{
delete []lpnewBmpDataBuf;
lpnewBmpDataBuf=NULL;
}
lpnewBmpDataBuf=new BYTE[nheapSize];
memcpy(lpnewBmpDataBuf,&m_newbmi,sizeof(BITMAPINFOHEADER));
DWORD* lp=(DWORD*)(lpnewBmpDataBuf+sizeof(BITMAPINFOHEADER));
*lp++=0x0000f800;
*lp++=0x000007e0;
*lp =0x0000001f;
for(i=0;i>3);
}
}
if(filesavebox.DoModal()!=IDOK) return;
strPathname=filesavebox.GetPathName();
if(!file.Open(strPathname,CFile::modeCreate|CFile::modeWrite))
{
MessageBox("Can not Create File!");
return;
}
file.Write(&m_bmf,sizeof(BITMAPFILEHEADER));
file.Write(lpnewBmpDataBuf,nheapSize);
file.Close();
Invalidate(TRUE);
}
1