void drawBitmapFormFile(CString BitmapFilePath,CRect rect,CDC* pDC)
{ //draw image into UI
HANDLE filehandle=::LoadImage(NULL,BitmapFilePath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
static BITMAP bmpInfo;
CBitmap bmp;
CDC dcMemory;
if(filehandle!=NULL)
{
if(bmp.Attach(filehandle))
{
bmp.GetBitmap(&bmpInfo);
if(!dcMemory.CreateCompatibleDC(pDC))
{
dcMemory.CreateCompatibleDC(NULL);
DeleteObject(bmp);
DeleteDC(dcMemory.m_hDC);
dcMemory.DeleteDC();
DeleteObject(filehandle);
return;
}
dcMemory.SelectObject(&bmp);
pDC->SetStretchBltMode(HALFTONE);
pDC->StretchBlt(rect.left,rect.top,rect.Width(),rect.Height(),&dcMemory,0,0,bmpInfo.bmWidth,bmpInfo.bmHeight,SRCCOPY);
bmp.Detach();
}
}
DeleteObject(bmp);
dcMemory.DeleteDC();
DeleteDC(dcMemory.m_hDC);
DeleteObject(filehandle);
}