使用画刷在背景中平铺位图

1.重载OnEraseBkgnd
修改return CEditView::OnEraseBkgnd(pDC);为return true;

2.从文件中加载位图 

BOOL CbackbrushView::OnEraseBkgnd(CDC *  pDC)
{
          HBITMAP bitmap
=(HBITMAP)::LoadImage(AfxGetInstanceHandle(),"c:/touxiang.bmp",IMAGE_BITMAP ,0,0,LR_DEFAULTSIZE | LR_LOADFROMFILE);
          CBrush brush;
          
//创建Pattern画刷
          brush.CreatePatternBrush(CBitmap::FromHandle(bitmap));
          CBrush
* pOldBrush;
         
//把画刷选入pDC上下文,并保存原先的画刷
          pOldBrush = (CBrush*)pDC->SelectObject(&brush);
         
//确定填充的矩形区域
          CRect rect;
          GetClientRect(rect);
         
//用位图填充
          pDC->FillRect(rect,&brush);
         
//恢复原先的画刷
          pDC->SelectObject(pOldBrush);
          
return true;
}

你可能感兴趣的:(c,image)