問(wèn)題描述
我想為 Windows 平臺(tái)編寫(xiě)一個(gè)截屏程序,但不確定如何截屏.我知道的唯一方法是使用 GDI,但我很好奇是否有其他方法可以解決這個(gè)問(wèn)題,如果有,哪種方法產(chǎn)生的開(kāi)銷(xiāo)最少?速度是重中之重.
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.
截屏程序?qū)⒂糜阡浿朴螒虍?huà)面,不過(guò),如果這確實(shí)縮小了選擇范圍,我仍然愿意接受超出此范圍的任何其他建議.畢竟,知識(shí)還不錯(cuò).
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.
編輯:我看到這篇文章:捕獲屏幕的各種方法一>.它向我介紹了執(zhí)行此操作的 Windows Media API 方式和執(zhí)行此操作的 DirectX 方式.它在結(jié)論中提到禁用硬件加速可以顯著提高捕獲應(yīng)用程序的性能.我很好奇這是為什么.誰(shuí)能幫我填一下缺失的空格?
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 之類的截屏程序使用它們自己的捕獲驅(qū)動(dòng)程序.有人能給我一個(gè)關(guān)于它是如何工作的以及為什么它更快的深入解釋嗎?我可能還需要有關(guān)實(shí)施此類內(nèi)容的指導(dǎo),但我確信無(wú)論如何都有現(xiàn)有文檔.
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.
此外,我現(xiàn)在知道 FRAPS 如何記錄屏幕.它掛鉤底層圖形 API 以從后臺(tái)緩沖區(qū)讀取.據(jù)我了解,這比從前端緩沖區(qū)讀取要快,因?yàn)槟菑南到y(tǒng) 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.
推薦答案
這是我用來(lái)收集單幀的,但如果你修改它并保持兩個(gè)目標(biāo)一直打開(kāi),那么你可以將它流式傳輸"到磁盤(pán)使用靜態(tài)計(jì)數(shù)器作為文件名.- 我不記得我在哪里找到的,但它已被修改,感謝誰(shuí)!
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();
}
這篇關(guān)于Windows 上最快的屏幕捕獲方法的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!