gpt4 book ai didi

c++ - 如何将 IDirect3DSurface9 或 LPD3DXBUFFER 以 JPG 格式保存到内存

转载 作者:行者123 更新时间:2023-11-30 04:04:49 36 4
gpt4 key购买 nike

我正在 try catch 游戏截图,我有代码:

LPDIRECT3DDEVICE9 Device;
D3DSURFACE_DESC screenDescription;

...

void Capture(){
IDirect3DSurface9* pRenderTarget;
IDirect3DSurface9* pDestTarget;

Device->GetRenderTarget(0, &pRenderTarget);
pRenderTarget->GetDesc(&screenDescription);

Device->CreateOffscreenPlainSurface(screenDescription.Width, screenDescription.Height, screenDescription.Format, D3DPOOL_SYSTEMMEM, &pDestTarget, NULL);
Device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_FORCE_DWORD, &pDestTarget);

char tName[200];
sprintf(tName, "%s_%d.jpg", "C:\\test", GetTickCount());
D3DXSaveSurfaceToFileA(tName, D3DXIFF_JPG, pDestTarget, NULL, NULL);

//LPD3DXBUFFER buffer;
//D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_JPG, pDestTarget, NULL, NULL);

pRenderTarget->Release();
pDestTarget->Release();

isCapturing = false;
}

使用 D3DXSaveSurfaceToFileA 保存到文件效果很好,但我想保存捕获的图像并将它们写入磁盘上另一个文件的末尾,而不是创建一个新文件。有没有办法将 IDirect3DSurface9LPD3DXBUFFER 转换为 JPG 字节?

最佳答案

好的,我找到了这段代码并且他可以工作:

LPD3DXBUFFER buffer;
D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_JPG, pDestTarget, NULL, NULL);
DWORD imSize = buffer->GetBufferSize();
void* imgBuffer = buffer->GetBufferPointer();

std::fstream out;
out.open(tName, std::ios_base::binary | std::ios_base::out);
out.write((char*)imgBuffer, imSize);
out.clear();
out.close();

关于c++ - 如何将 IDirect3DSurface9 或 LPD3DXBUFFER 以 JPG 格式保存到内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23591608/

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