MFC view显示Png图片(bitmap方式显示)


包含头文件

#include "atlimage.h"


在OnPaint中代码如下:

void CDialogTest::OnPaint()
{
		CBitmap bitmap;
		CDC dcMemory;
		int result;
		bitmap.CreateBitmap(IMAGER_SIZE_X, IMAGER_SIZE_Y, 1, 32, m_lpBuf);	
		
		result = bitmap.SetBitmapBits(IMAGER_SIZE_X*IMAGER_SIZE_Y*4, m_lpBuf);
		dcMemory.CreateCompatibleDC(m_pDC);
		CBitmap *pbmpOld = dcMemory.SelectObject(&bitmap);
		//m_pDC->StretchBlt(0,0,目宽,目高,&dcMemory,0,0,源宽,源高,SRCCOPY);
		m_pDC->BitBlt(0, 0, IMAGER_SIZE_X, IMAGER_SIZE_Y, &dcMemory, 0, 0, SRCCOPY);
		//m_pDC->StretchBlt(0,0,IMAGER_SIZE_X/2,IMAGER_SIZE_Y/2,&dcMemory,0,0,IMAGER_SIZE_X,IMAGER_SIZE_Y,SRCCOPY);
		dcMemory.SelectObject(pbmpOld);

}

加载图片并转成bimap格式

void CDialogTest::LoadImage()
{
	   HBITMAP hBitmap;
	   CString filename;
	   CString BMPFolder;
	   CString str;

	   CImage layerPng;

	   str.Format("layer (%d).png", layernum);
	 
	   filename = BMPFolder + "\\" + str;

	   layerPng.Load(filename);
	   hBitmap=layerPng.Detach();
	   CBitmap bmp;
	   BITMAP l_bitMap;
	   bmp.Attach(hBitmap);
	   bmp.GetBitmap(&l_bitMap);

	   int height = l_bitMap.bmHeight;
	   int width = l_bitMap.bmWidth;

	   bmp.GetBitmapBits(IMAGER_SIZE_X*IMAGER_SIZE_Y*4,m_lpBuf);
}


你可能感兴趣的:(MFC,C/C++,图片显示)