[求助]用DirectX的什么函数可以把内存中的图片显示到屏幕?
用DirectX的什么函数可以把内存中的图片显示到屏幕?
Blt()和BltFast()
不过在这之前要把图片加到表面上:
BOOL LoadBMPSurface(LPDIRECTDRAWSURFACE7 &lpDDS,LPCSTR pszBitmapFile)
{
HBITMAP hbm;
BITMAP bm;
HDC hdc1,hdc2;
HRESULT hr;
if(lpDDS==NULL)
{
MessageBox(m_hWnd,"未创建的DirectDrawNULL离屏表面","出错啦",0);
return FALSE;
}
hbm=(HBITMAP)LoadImage(NULL,pszBitmapFile,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
if(hbm==NULL)
{
MessageBox(m_hWnd,"无法加载Bitmap文件","出错啦啦",0);
DeleteObject(hbm);
return FALSE;
}
hdc1=CreateCompatibleDC(NULL);
if(hdc1==NULL)
{
MessageBox(m_hWnd,"无法创建兼容DC","出错啦",0);
DeleteObject(hbm);
return FALSE;
}
SelectObject(hdc1,hbm);
GetObject(hbm,sizeof(bm),&bm);
DDSURFACEDESC2 ddsd;
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize=sizeof(ddsd);
hr=lpDDS->GetSurfaceDesc(&ddsd);
if(hr!=DD_OK)
{
MessageBox(m_hWnd,"无法得到表面信息","出错啦",0);
DeleteDC(hdc1);
if(hbm)
DeleteObject(hbm);
return FALSE;
}
hr=lpDDS->GetDC(&hdc2);
if(hr!=DD_OK)
{
MessageBox(m_hWnd,"无法创建表面相关DC","出错啦",0);
DeleteDC(hdc1);
if(hbm)
DeleteObject(hbm);
return FALSE;
}
StretchBlt(hdc2,0,0,ddsd.dwWidth,ddsd.dwHeight,hdc1,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
lpDDS->ReleaseDC(hdc2);
if(hbm)
DeleteObject(hbm);
DeleteDC(hdc1);
return TRUE;
}
之后用Blt()或BltFast()把加有图片的那个表画贴到主表画上