gpt4 book ai didi

c++ - 我如何从 HBITMAP 获取字节数组

转载 作者:行者123 更新时间:2023-11-28 08:10:21 25 4
gpt4 key购买 nike

我的环境:
win32
视觉 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,无效**)

或者可以用其他方法的组合来做到这一点?

最佳答案

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

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

关于c++ - 我如何从 HBITMAP 获取字节数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9301352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com