問題描述
我想為 Windows 平臺編寫一個截屏程序,但不確定如何截屏.我知道的唯一方法是使用 GDI,但我很好奇是否有其他方法可以解決這個問題,如果有,哪種方法產生的開銷最少?速度是重中之重.
I want to write a screencasting program for the Windows platform, but am unsure of how to capture the screen. The only method I'm aware of is to use GDI, but I'm curious whether there are other ways to go about this, and, if there are, which incurs the least overhead? Speed is a priority.
截屏程序將用于錄制游戲畫面,不過,如果這確實縮小了選擇范圍,我仍然愿意接受超出此范圍的任何其他建議.畢竟,知識還不錯.
The screencasting program will be for recording game footage, although, if this does narrow down the options, I'm still open for any other suggestions that fall out of this scope. Knowledge isn't bad, after all.
編輯:我看到這篇文章:捕獲屏幕的各種方法一>.它向我介紹了執行此操作的 Windows Media API 方式和執行此操作的 DirectX 方式.它在結論中提到禁用硬件加速可以顯著提高捕獲應用程序的性能.我很好奇這是為什么.誰能幫我填一下缺失的空格?
Edit: I came across this article: Various methods for capturing the screen. It has introduced me to the Windows Media API way of doing it and the DirectX way of doing it. It mentions in the Conclusion that disabling hardware acceleration could drastically improve the performance of the capture application. I'm curious as to why this is. Could anyone fill in the missing blanks for me?
編輯:我讀到諸如 Camtasia 之類的截屏程序使用它們自己的捕獲驅動程序.有人能給我一個關于它是如何工作的以及為什么它更快的深入解釋嗎?我可能還需要有關實施此類內容的指導,但我確信無論如何都有現有文檔.
Edit: I read that screencasting programs such as Camtasia use their own capture driver. Could someone give me an in-depth explanation on how it works, and why it is faster? I may also need guidance on implementing something like that, but I'm sure there is existing documentation anyway.
此外,我現在知道 FRAPS 如何記錄屏幕.它掛鉤底層圖形 API 以從后臺緩沖區讀取.據我了解,這比從前端緩沖區讀取要快,因為您是從系統 RAM 讀取,而不是從視頻 RAM 讀取.您可以閱讀文章 這里.
Also, I now know how FRAPS records the screen. It hooks the underlying graphics API to read from the back buffer. From what I understand, this is faster than reading from the front buffer, because you are reading from system RAM, rather than video RAM. You can read the article here.
推薦答案
這是我用來收集單幀的,但如果你修改它并保持兩個目標一直打開,那么你可以將它流式傳輸"到磁盤使用靜態計數器作為文件名.- 我不記得我在哪里找到的,但它已被修改,感謝誰!
This is what I use to collect single frames, but if you modify this and keep the two targets open all the time then you could "stream" it to disk using a static counter for the file name. - I can't recall where I found this, but it has been modified, thanks to whoever!
void dump_buffer()
{
IDirect3DSurface9* pRenderTarget=NULL;
IDirect3DSurface9* pDestTarget=NULL;
const char file[] = "Pickture.bmp";
// sanity checks.
if (Device == NULL)
return;
// get the render target surface.
HRESULT hr = Device->GetRenderTarget(0, &pRenderTarget);
// get the current adapter display mode.
//hr = pDirect3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddisplaymode);
// create a destination surface.
hr = Device->CreateOffscreenPlainSurface(DisplayMde.Width,
DisplayMde.Height,
DisplayMde.Format,
D3DPOOL_SYSTEMMEM,
&pDestTarget,
NULL);
//copy the render target to the destination surface.
hr = Device->GetRenderTargetData(pRenderTarget, pDestTarget);
//save its contents to a bitmap file.
hr = D3DXSaveSurfaceToFile(file,
D3DXIFF_BMP,
pDestTarget,
NULL,
NULL);
// clean up.
pRenderTarget->Release();
pDestTarget->Release();
}
這篇關于Windows 上最快的屏幕捕獲方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!