欢迎来到我的博客https://www.cnblogs.com/veis/

https://www.cnblogs.com/veis/p/14182037.html

MFC中加载位图

(1)使用BitBlt

void CBRUSHTESTDlg::OnPaint()
{
	CPaintDC dc(this);
	CBitmap bmp;
	bmp.LoadBitmap(IDB_BITMAP1);
	BITMAP bitmap;
	int size = bmp.GetBitmap(&bitmap);
	CDC memDC;
	memDC.CreateCompatibleDC(&dc);
	memDC.SelectObject(&bmp);
	dc.BitBlt(10, 10, bitmap.bmWidth, bitmap.bmHeight, &memDC, 0, 0, SRCCOPY);    //向窗口中绘制位图
}

  

 

(2)使用StretchBlt

void CBRUSHTESTDlg::OnPaint()
{
	CPaintDC dc(this);
	CBitmap bmp;
	bmp.LoadBitmap(IDB_BITMAP1);
	BITMAP bitmap;
	int size = bmp.GetBitmap(&bitmap);
	CDC memDC;
	memDC.CreateCompatibleDC(&dc);
	memDC.SelectObject(&bmp);

	dc.SetStretchBltMode(STRETCH_HALFTONE);
	dc.StretchBlt(0, 0, bitmap.bmWidth, bitmap.bmHeight, &memDC, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);    //向窗口中绘制位图
}

  

  

posted @ 2020-05-06 18:33  veis  阅读(692)  评论(0编辑  收藏  举报