文件名称:彩色与黑白图片互转
文件大小:1.95MB
文件格式:RAR
更新时间:2015-02-04 10:22:42
彩色与黑白图片互转
if(strPathName == "")
return false;
BITMAPFILEHEADER * pBFH;
BITMAPINFOHEADER * pBIH;
CFile file(strPathName,CFile::modeCreate | CFile::modeNoTruncate | CFile::modeRead);
DWORD filelength = file.GetLength();
// 分配一块内存用于装入图象数据
if(m_hDib!=NULL)
::GlobalFree(m_hDib);
m_hDib = :: GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,filelength);
if(m_hDib==NULL)
{
return (FALSE);
}
m_pDib = (BYTE *)::GlobalLock(m_hDib);
if(m_pDib==NULL)
{
::GlobalFree(m_hDib);
return (FALSE);
}
// 将图象数据读入内存
file.Read(m_pDib,(UINT)filelength);
file.Close();
// 读入头信息
pBFH = (BITMAPFILEHEADER *) m_pDib;
pBIH = (BITMAPINFOHEADER *) (m_pDib+sizeof(BITMAPFILEHEADER));
WORD bfType = pBFH->bfType;
if(bfType!=19778) // "BM"标志
{
AfxMessageBox("Not a valid BMP image!");
return FALSE;
}
//得到位图信息
m_nWidth = (int)pBIH->biWidth;
m_nHeight = (int)pBIH->biHeight;
m_nBits = (int)pBIH->biBitCount;
m_nColors = (int)pBIH->biClrUsed;
if(m_nColors == 0)
{
if(m_nBits <= 8)
m_nColors = 1 << m_nBits;
}
m_strPathName = strPathName;
// 载入调色板
m_Palette.DeleteObject();
if( m_nBits <= 8 )
m_nPaletteInBytes = m_nColors * sizeof( RGBQUAD );
if( m_nBits <= 8 )
{
RGBQUAD *pRGBPalette;
pRGBPalette = ( RGBQUAD * )&m_pDib[ sizeof( BITMAPFILEHEADER ) + sizeof( BITMAPINFOHEADER ) ];
LOGPALETTE *pLogPalette;
pLogPalette = ( LOGPALETTE * )new char[ sizeof( LOGPALETTE ) + m_nColors * sizeof( PALETTEENTRY ) ];
pLogPalette->palVersion = 0x300;
pLogPalette->palNumEntries = ( unsigned short )m_nColors;
for(int i=0; i
【文件预览】:
7df38c6da54a
----(old)Image.cpp(23KB)
----ImageTest.rc(12KB)
----res()
--------ImageTest.rc2(401B)
--------Toolbar.bmp(1KB)
--------ImageTestDoc.ico(1KB)
--------ImageTest.ico(1KB)
----(old)Image.h(3KB)
----ImageTest.h(1KB)
----ImageTest.opt(175KB)
----Image.cpp(38KB)
----ImageTestView.h(2KB)
----ImageTest.cpp(4KB)
----ImageTestView.cpp(4KB)
----StdAfx.cpp(211B)
----MainFrm.cpp(2KB)
----Image.h(4KB)
----resource.h(690B)
----ImageTest.plg(252B)
----ImageTest.clw(2KB)
----MainFrm.h(2KB)
----ImageTest.dsw(543B)
----StdAfx.h(1KB)
----ImageTestDoc.cpp(6KB)
----ImageTestDoc.h(2KB)
----ImageTest.ncb(177KB)
----ImageTest.dsp(5KB)
----Debug()
--------ImageTest.ilk(363KB)
--------StdAfx.obj(103KB)
--------Image.obj(52KB)
--------ImageTest.pch(5.25MB)
--------ImageTest.pdb(369KB)
--------vc60.idb(201KB)
--------ImageTestView.obj(24KB)
--------vc60.pdb(356KB)
--------ImageTest.obj(23KB)
--------ImageTest.exe(140KB)
--------ImageTest.res(7KB)
--------MainFrm.obj(20KB)
--------ImageTestDoc.obj(27KB)
----ImageTest.aps(29KB)
----ReadMe.txt(4KB)