?? cdib.cpp
字號:
#include "stdafx.h"
#include "LaneSoftDoc.h"
#include "LaneSoftView.h"
#include "CDIB.h"
extern CLaneSoftView * m_pMainView;
CDIB::CDIB()
{
m_pBMI = NULL;
m_pDIBData = NULL;
}
CDIB::~CDIB()
{
if(m_pBMI != NULL)
delete m_pBMI;
if(m_pDIBData != NULL)
delete m_pDIBData;
}
BOOL CDIB::LoadFromFile(LPCTSTR lpszFileName)
{
CFile file;
BITMAPINFO * pBMI = NULL;
BYTE * pDIBData = NULL;
if(!file.Open(lpszFileName,CFile::modeRead|CFile::typeBinary))
{
AfxMessageBox("無法打開文件");
return FALSE;
}
BITMAPFILEHEADER bfh;
if(file.Read(&bfh,sizeof(bfh)) != sizeof(bfh))
{
AfxMessageBox("讀文件出錯");
return FALSE;
}
if(bfh.bfType != 0x4d42)
{
AfxMessageBox("不是BMP文件");
return FALSE;
}
BITMAPINFOHEADER bih;
if(file.Read(&bih,sizeof(bih)) != sizeof(bih))
{
AfxMessageBox("讀文件出錯");
return FALSE;
}
if( bih.biBitCount != 24 )
{
AfxMessageBox("不是24位真彩色位圖");
return FALSE;
}
pBMI = (BITMAPINFO *)new char[sizeof(BITMAPINFOHEADER)];
if(!pBMI)
{
AfxMessageBox("分配內(nèi)存出錯");
return FALSE;
}
memcpy(pBMI,&bih,sizeof(BITMAPINFOHEADER));
DWORD dataBytes = bfh.bfSize - bfh.bfOffBits;
pDIBData = (BYTE *)new char[dataBytes];
if(!pDIBData)
{
AfxMessageBox("分配內(nèi)存出錯");
delete pBMI;
delete pDIBData;
return FALSE;
}
if(file.ReadHuge(pDIBData,dataBytes) != dataBytes)
{
AfxMessageBox("讀文件出錯");
delete pBMI;
delete pDIBData;
return FALSE;
}
file.Close();
if(m_pBMI != NULL)
delete m_pBMI;
m_pBMI = pBMI;
if(m_pDIBData != NULL)
delete m_pDIBData;
m_pDIBData = pDIBData;
m_pDIBOffset = m_pDIBData + bfh.bfOffBits - sizeof(BITMAPINFOHEADER)
-sizeof(BITMAPFILEHEADER);
return TRUE;
}
void CDIB::ShowDIB(CDC *pDC,int nLeft,int nTop,int nWidth,int nHeight)
{
pDC->SetStretchBltMode(COLORONCOLOR);
StretchDIBits(pDC->GetSafeHdc(),nLeft,nTop,nWidth,nHeight,
0,0,GetDIBWidth(),GetDIBHeight(),
m_pDIBOffset,m_pBMI,DIB_RGB_COLORS,SRCCOPY);
}
void CDIB::PasteDIB(CDC *pDC,int nLeft,int nTop,int nWidth,int nHeight)
{
BYTE * pDIBData = NULL;
DWORD dataBytes = GetDIBWidth() * GetDIBHeight() * 3l;
pDIBData = (BYTE *)new char[dataBytes];
if(!pDIBData)
{
AfxMessageBox("分配內(nèi)存出錯");
return ;
}
DWORD i;
for(i = 0 ; i < dataBytes ; i++)
{
if(m_pDIBOffset[i] == 0xff)
pDIBData[i] = 0;
else
pDIBData[i] = m_pDIBOffset[i];
}
m_pMainView->m_pFrameDlg->m_Video_Win.SendMessage(WM_START_VIDEO,1,0);
pDC->SetStretchBltMode(COLORONCOLOR);
StretchDIBits(pDC->GetSafeHdc(),nLeft,nTop,nWidth,nHeight,
0,0,GetDIBWidth(),GetDIBHeight(),
pDIBData,m_pBMI,DIB_RGB_COLORS,SRCPAINT );
StretchDIBits(pDC->GetSafeHdc(),nLeft,nTop,nWidth,nHeight,
0,0,GetDIBWidth(),GetDIBHeight(),
m_pDIBOffset,m_pBMI,DIB_RGB_COLORS,SRCAND);
m_pMainView->m_pFrameDlg->m_Video_Win.SendMessage(WM_START_VIDEO,0,0);
delete [] pDIBData;
}
void CDIB::PasteDIB1(CDC *pDC,int nLeft,int nTop,int nWidth,int nHeight)
{
BYTE * pDIBData = NULL;
DWORD dataBytes = GetDIBWidth() * GetDIBHeight() * 3l;
pDIBData = (BYTE *)new char[dataBytes];
if(!pDIBData)
{
AfxMessageBox("分配內(nèi)存出錯");
return ;
}
DWORD i;
for(i = 0 ; i < dataBytes ; i++)
{
if(m_pDIBOffset[i] == 0xff)
pDIBData[i] = 0;
else
pDIBData[i] = m_pDIBOffset[i];
}
StretchDIBits(pDC->GetSafeHdc(),nLeft,nTop,nWidth,nHeight,
0,0,GetDIBWidth(),GetDIBHeight(),
pDIBData,m_pBMI,DIB_RGB_COLORS,SRCPAINT );
pDC->SetStretchBltMode(COLORONCOLOR);
StretchDIBits(pDC->GetSafeHdc(),nLeft,nTop,nWidth,nHeight,
0,0,GetDIBWidth(),GetDIBHeight(),
m_pDIBOffset,m_pBMI,DIB_RGB_COLORS,SRCAND);
delete [] pDIBData;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -