我怎么能从HBITMAP获得字节数组

时间:2012-02-15 21:03:59

标签: c++ visual-studio api winapi directx

我的环境:
Win32的
visual c ++
的DirectX

我需要将另一个应用程序的面部映射到我的应用程序的纹理 例如,我的Internet Explorer屏幕出现在我的DirectX Cube的纹理上,它会实时更新。

我的方法是下一个:

//in DirectX Rendering Loop...

HWND hSrc = FindWindow(NULL, _T("application's classname"));
HDC hdc = GetDC(hSrc);

RECT targetRect;
GetClientRect(hSrc, &targetRect);
HBITMAP hBitmap = CreateCompatibleBitmap(hdc,targetRect.right,targetRect.bottom);
//now, target application's window is 'hBitmap'

LPDIRECT3DTEXTURE9 ptxt = NULL;    //my destination texture
if( SUCCEEDED(D3DXCreateTexture(gpDevice,targetRect.right, targetRect.bottom, 
        0, 0, D3DFMT_A8B8G8R8, D3DPOOL_MANAGED,&ptxt)))
        {
            D3DLOCKED_RECT lr;
            HRESULT hr = ptxt->LockRect(0,&lr,NULL,D3DLOCK_DISCARD);

             //TODO : memcpy(lr.pBits , 'Start pointer of Bit-Array' , targetRect.right*targetRect.bottom*4); //mydesktop's color is 32bit truecolor (= *4)

            ptxt->UnlockRect(0);
        }

问题:
如何从HBITMAP格式获取字节数组? win32api中有这样的方法吗?

GetByteArray(HBITMAP,void **)

或者可以用其他方法组成吗?

1 个答案:

答案 0 :(得分:1)

CreateCompatibleBitmap创建一个DDB,您无权访问这些位。请尝试使用CreateDIBSection

另请注意,如上所述,您尚未在位图中绘制任何内容。

相关问题