资源简介
如题,内容主要也就是dib.h和dib.cpp两个文件,之前看到其他人传的不是很全,加上dib.cpp就是这样
代码片段和文件信息
// Dib.cpp: implementation of the CDib class.
//
//////////////////////////////////////////////////////////////////////
#include “StdAfx.h“
#include “Dib.h“
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDib::CDib()
{
m_hDrawDib=NULL;
m_pDib=NULL;
}
CDib::~CDib()
{
Close();
}
void CDib::Draw(CDC *pDCint nWidth int nHeight)
{
if(m_pDib!=NULL)
{
ASSERT(IsValid());
DrawDibRealize(m_hDrawDibpDC->GetSafeHdc()TRUE);
DrawDibDraw(m_hDrawDibpDC->GetSafeHdc()
0 //desktop left
0 //desktop top
nWidth
nHeight
(BITMAPINFOHEADER *)m_pDib
(LPVOID) GetBits()
0 //source left
0 //source top
((BITMAPINFOHEADER *)m_pDib)->biWidth
((BITMAPINFOHEADER *)m_pDib)->biHeight
DDF_BACKGROUNDPAL);
}
}
CSize CDib::GetSize()
{
return CSize(((BITMAPINFOHEADER *)m_pDib)->biWidth
((BITMAPINFOHEADER *)m_pDib)->biHeight);
}
LONG CDib::GetWidth()
{
return ((BITMAPINFOHEADER *)m_pDib)->biWidth;
}
LONG CDib::GetHeight()
{
return ((BITMAPINFOHEADER *)m_pDib)->biHeight;
}
void CDib::Close()
{
if(m_hDrawDib!=NULL)
{
DrawDibClose(m_hDrawDib);
m_hDrawDib=NULL;
}
if(m_pDib!=NULL)
{
delete m_pDib;
m_pDib=NULL;
}
}
BOOL CDib::Open(const char * pzFileName)
{
// BITMAPFILEHEADER bmpFileHeader;
CFile file;
int nBmpFileHeaderSize;
Close();
//drawdibopen initialize the diradib library and
//returns a handle for all drawdib operations
if(!(m_hDrawDib=DrawDibOpen()))
goto exit;
//open and read the DIB file header
nBmpFileHeaderSize=sizeof(BITMAPFILEHEADER);
if(!file.Open(pzFileNameCFile::modeRead | CFile::typeBinary))
goto exit;
if(file.Read((void *)&bmpFileHeadernBmpFileHeaderSize)!=(UINT)nBmpFileHeaderSize)
goto failure;
//validate the DIB file header by checking the first
//two characters for the signature “BM“
if(bmpFileHeader.bfType!=*((WORD *)“BM“))
goto failure;
//allocate a big chuck of global memory to store the DIB
m_pDib=(BYTE *)new char [bmpFileHeader.bfSize-nBmpFileHeaderSize];
//allocate memory fail
if(!m_pDib)
goto failure;
//read the dib into the buffer at a time using ReadHuge
file.ReadHuge(m_pDibbmpFileHeader.bfSize-nBmpFileHeaderSize);
if(((BITMAPINFOHEADER *)m_pDib)->biSizeImage==0)
{
//the application that create this bitmap didn‘t fill
//in the biSizeImage field. Let‘s fill it
//in even though the DrawDib * functions don‘t need it.
BITMAPINFOHEADER *pDib=(BITMAPINFOHEADER *)m_pDib;
//scan lines must be DWord aligned hence the strange bit stuff
pDib->biSizeImage=((((pDib->biWidth*pDib->biBitCount)+31)&~31)>>3)*pDib->biHeight;
}
m_pDibBits=GetBits();
file.Close();
ret
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4429 2012-07-12 17:19 dib.cpp
文件 964 2012-07-12 17:19 dib.h
----------- --------- ---------- ----- ----
5393 2
评论
共有 条评论