久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <small id='AoZdD'></small><noframes id='AoZdD'>

    1. <i id='AoZdD'><tr id='AoZdD'><dt id='AoZdD'><q id='AoZdD'><span id='AoZdD'><b id='AoZdD'><form id='AoZdD'><ins id='AoZdD'></ins><ul id='AoZdD'></ul><sub id='AoZdD'></sub></form><legend id='AoZdD'></legend><bdo id='AoZdD'><pre id='AoZdD'><center id='AoZdD'></center></pre></bdo></b><th id='AoZdD'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='AoZdD'><tfoot id='AoZdD'></tfoot><dl id='AoZdD'><fieldset id='AoZdD'></fieldset></dl></div>
    2. <tfoot id='AoZdD'></tfoot>

      • <bdo id='AoZdD'></bdo><ul id='AoZdD'></ul>
      <legend id='AoZdD'><style id='AoZdD'><dir id='AoZdD'><q id='AoZdD'></q></dir></style></legend>
    3. 使用 DirectX 捕獲屏幕

      Capture screen using DirectX(使用 DirectX 捕獲屏幕)
      <i id='F9hG3'><tr id='F9hG3'><dt id='F9hG3'><q id='F9hG3'><span id='F9hG3'><b id='F9hG3'><form id='F9hG3'><ins id='F9hG3'></ins><ul id='F9hG3'></ul><sub id='F9hG3'></sub></form><legend id='F9hG3'></legend><bdo id='F9hG3'><pre id='F9hG3'><center id='F9hG3'></center></pre></bdo></b><th id='F9hG3'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='F9hG3'><tfoot id='F9hG3'></tfoot><dl id='F9hG3'><fieldset id='F9hG3'></fieldset></dl></div>
        <tbody id='F9hG3'></tbody>

                <bdo id='F9hG3'></bdo><ul id='F9hG3'></ul>

                <small id='F9hG3'></small><noframes id='F9hG3'>

              • <tfoot id='F9hG3'></tfoot>
              • <legend id='F9hG3'><style id='F9hG3'><dir id='F9hG3'><q id='F9hG3'></q></dir></style></legend>
                本文介紹了使用 DirectX 捕獲屏幕的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我知道如何使用 GDI 來捕獲屏幕,但是它非常慢(它幾乎不能捕獲 10 fps)

                I know how to use GDI to capture screen, however it is very slow (it barely captures 10 fps)

                我了解到 DirectX 提供了最佳速度.但在我開始學習 DirectX 之前,我想測試一個示例,看看它是否真的那么快.

                I have read that DirectX offers the best speed. But before I start learning DirectX I wanted to test a sample to see if it is really that fast.

                我發現這個問題提供了一個示例代碼來做到這一點:

                I have found this question that offers a sample code to do that:

                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();
                }
                

                我已嘗試包含所需的文件.但是,并非所有這些都可以包含在內(例如 #include ).

                I have tried to include the required files. However not all of them can be included (for example #include <D3dx9tex.h>).

                任何人都可以提供一個工作示例,其中包含所有必需的包含或指向我應該安裝哪些庫.

                Can anyone provide a working example that has all of the required includes or point me to what libraries I should install.

                我在 Windows 7 Ultimate (x64) 上使用 Visual C++ 2010 Express.

                I am using Visual C++ 2010 Express on Windows 7 Ultimate (x64).

                另外,這段代碼并不完整,比如Device標識符是什么?!

                Also, this code is not complete, for example what is the Device identifier?!

                推薦答案

                以下是一些使用 DirectX 9 捕獲屏幕的示例代碼.您不必安裝任何 SDK(除了 Visual Studio 附帶的標準文件,盡管我沒有測試 VS 2010).

                Here is some sample code to capture the screen with DirectX 9. You shouldn't have to install any SDK (except the standard files that come with Visual Studio, although I didn't tested VS 2010).

                只需創建一個簡單的 Win32 控制臺應用程序,在 stdafx.h 文件中添加以下內容:

                Just create a simple Win32 console application, add the following in the stdafx.h file:

                  #include <Wincodec.h>             // we use WIC for saving images
                  #include <d3d9.h>                 // DirectX 9 header
                  #pragma comment(lib, "d3d9.lib")  // link to DirectX 9 library
                

                這是示例主要實現

                  int _tmain(int argc, _TCHAR* argv[])
                  {
                    HRESULT hr = Direct3D9TakeScreenshots(D3DADAPTER_DEFAULT, 10);
                    return 0;
                  }
                

                這將捕獲 10 倍屏幕,并將cap%i.png"圖像保存在磁盤上.它還會顯示為此花費的時間(保存圖像不計入該時間,只計算屏幕截圖).在我的(桌面 Windows 8 - Dell Precision M2800/i7-4810MQ-2.80GHz/Intel HD 4600,這是一臺非常糟糕的機器......)機器上,它需要在大約 4 秒內捕獲 100 個 1920x1080,所以大約 20/25 fps.

                What this will do is capture 10 times the screen, and save "cap%i.png" images on the disk. It will also display the time taken for this (saving images is not counted in that time, only screen captures). On my (desktop windows 8 - Dell Precision M2800/i7-4810MQ-2.80GHz/Intel HD 4600 which is a pretty crappy machine...) machine, it takes 100 1920x1080 captures in ~4sec, so around 20/25 fps.

                  HRESULT Direct3D9TakeScreenshots(UINT adapter, UINT count)
                  {
                    HRESULT hr = S_OK;
                    IDirect3D9 *d3d = nullptr;
                    IDirect3DDevice9 *device = nullptr;
                    IDirect3DSurface9 *surface = nullptr;
                    D3DPRESENT_PARAMETERS parameters = { 0 };
                    D3DDISPLAYMODE mode;
                    D3DLOCKED_RECT rc;
                    UINT pitch;
                    SYSTEMTIME st;
                    LPBYTE *shots = nullptr;
                
                    // init D3D and get screen size
                    d3d = Direct3DCreate9(D3D_SDK_VERSION);
                    HRCHECK(d3d->GetAdapterDisplayMode(adapter, &mode));
                
                    parameters.Windowed = TRUE;
                    parameters.BackBufferCount = 1;
                    parameters.BackBufferHeight = mode.Height;
                    parameters.BackBufferWidth = mode.Width;
                    parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
                    parameters.hDeviceWindow = NULL;
                
                    // create device & capture surface
                    HRCHECK(d3d->CreateDevice(adapter, D3DDEVTYPE_HAL, NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, ¶meters, &device));
                    HRCHECK(device->CreateOffscreenPlainSurface(mode.Width, mode.Height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surface, nullptr));
                
                    // compute the required buffer size
                    HRCHECK(surface->LockRect(&rc, NULL, 0));
                    pitch = rc.Pitch;
                    HRCHECK(surface->UnlockRect());
                
                    // allocate screenshots buffers
                    shots = new LPBYTE[count];
                    for (UINT i = 0; i < count; i++)
                    {
                      shots[i] = new BYTE[pitch * mode.Height];
                    }
                
                    GetSystemTime(&st); // measure the time we spend doing <count> captures
                    wprintf(L"%i:%i:%i.%i
                ", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
                    for (UINT i = 0; i < count; i++)
                    {
                      // get the data
                      HRCHECK(device->GetFrontBufferData(0, surface));
                
                      // copy it into our buffers
                      HRCHECK(surface->LockRect(&rc, NULL, 0));
                      CopyMemory(shots[i], rc.pBits, rc.Pitch * mode.Height);
                      HRCHECK(surface->UnlockRect());
                    }
                    GetSystemTime(&st);
                    wprintf(L"%i:%i:%i.%i
                ", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
                
                    // save all screenshots
                    for (UINT i = 0; i < count; i++)
                    {
                      WCHAR file[100];
                      wsprintf(file, L"cap%i.png", i);
                      HRCHECK(SavePixelsToFile32bppPBGRA(mode.Width, mode.Height, pitch, shots[i], file, GUID_ContainerFormatPng));
                    }
                
                  cleanup:
                    if (shots != nullptr)
                    {
                      for (UINT i = 0; i < count; i++)
                      {
                        delete shots[i];
                      }
                      delete[] shots;
                    }
                    RELEASE(surface);
                    RELEASE(device);
                    RELEASE(d3d);
                    return hr;
                  }
                

                請注意,此代碼隱式鏈接到 WIC(包含一個成像庫使用 Windows 很長一段時間)來保存圖像文件(因此您不需要需要安裝舊 DirectX SDK 的著名 D3DXSaveSurfaceToFile):

                Note this code implicitely links to WIC (an imaging library included with Windows for quite a time now) to save the image files (so you don't need the famous D3DXSaveSurfaceToFile that require old DirectX SDKs to be installed):

                  HRESULT SavePixelsToFile32bppPBGRA(UINT width, UINT height, UINT stride, LPBYTE pixels, LPWSTR filePath, const GUID &format)
                  {
                    if (!filePath || !pixels)
                      return E_INVALIDARG;
                
                    HRESULT hr = S_OK;
                    IWICImagingFactory *factory = nullptr;
                    IWICBitmapEncoder *encoder = nullptr;
                    IWICBitmapFrameEncode *frame = nullptr;
                    IWICStream *stream = nullptr;
                    GUID pf = GUID_WICPixelFormat32bppPBGRA;
                    BOOL coInit = CoInitialize(nullptr);
                
                    HRCHECK(CoCreateInstance(CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&factory)));
                    HRCHECK(factory->CreateStream(&stream));
                    HRCHECK(stream->InitializeFromFilename(filePath, GENERIC_WRITE));
                    HRCHECK(factory->CreateEncoder(format, nullptr, &encoder));
                    HRCHECK(encoder->Initialize(stream, WICBitmapEncoderNoCache));
                    HRCHECK(encoder->CreateNewFrame(&frame, nullptr)); // we don't use options here
                    HRCHECK(frame->Initialize(nullptr)); // we dont' use any options here
                    HRCHECK(frame->SetSize(width, height));
                    HRCHECK(frame->SetPixelFormat(&pf));
                    HRCHECK(frame->WritePixels(height, stride, stride * height, pixels));
                    HRCHECK(frame->Commit());
                    HRCHECK(encoder->Commit());
                
                  cleanup:
                    RELEASE(stream);
                    RELEASE(frame);
                    RELEASE(encoder);
                    RELEASE(factory);
                    if (coInit) CoUninitialize();
                    return hr;
                  }
                

                還有一些我用過的宏:

                  #define WIDEN2(x) L ## x
                  #define WIDEN(x) WIDEN2(x)
                  #define __WFILE__ WIDEN(__FILE__)
                  #define HRCHECK(__expr) {hr=(__expr);if(FAILED(hr)){wprintf(L"FAILURE 0x%08X (%i)
                	line: %u file: '%s'
                	expr: '" WIDEN(#__expr) L"'
                ",hr, hr, __LINE__,__WFILE__);goto cleanup;}}
                  #define RELEASE(__p) {if(__p!=nullptr){__p->Release();__p=nullptr;}}
                

                注意:對于 Windows 8+ 客戶端,應放棄所有這些(WIC 除外)以支持 桌面復制 API.

                Note: for Windows 8+ clients, all these (except WIC) should be dropped in favor of the Desktop Duplication API.

                這篇關于使用 DirectX 捕獲屏幕的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                In what ways do C++ exceptions slow down code when there are no exceptions thown?(當沒有異常時,C++ 異常會以何種方式減慢代碼速度?)
                Why catch an exception as reference-to-const?(為什么要捕獲異常作為對 const 的引用?)
                When and how should I use exception handling?(我應該何時以及如何使用異常處理?)
                Scope of exception object in C++(C++中異常對象的范圍)
                Catching exceptions from a constructor#39;s initializer list(從構造函數的初始化列表中捕獲異常)
                Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 說明符 C++11 noexcept 之間的區別)
                    <bdo id='szuhL'></bdo><ul id='szuhL'></ul>

                      <tbody id='szuhL'></tbody>

                    1. <i id='szuhL'><tr id='szuhL'><dt id='szuhL'><q id='szuhL'><span id='szuhL'><b id='szuhL'><form id='szuhL'><ins id='szuhL'></ins><ul id='szuhL'></ul><sub id='szuhL'></sub></form><legend id='szuhL'></legend><bdo id='szuhL'><pre id='szuhL'><center id='szuhL'></center></pre></bdo></b><th id='szuhL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='szuhL'><tfoot id='szuhL'></tfoot><dl id='szuhL'><fieldset id='szuhL'></fieldset></dl></div>

                    2. <tfoot id='szuhL'></tfoot>

                      <small id='szuhL'></small><noframes id='szuhL'>

                        <legend id='szuhL'><style id='szuhL'><dir id='szuhL'><q id='szuhL'></q></dir></style></legend>

                          主站蜘蛛池模板: 国产午夜在线观看 | 久久久久久久久一区 | 阿v视频在线观看 | 久久久久国产成人精品亚洲午夜 | 日韩欧美网 | 夫妻午夜影院 | 久草网址 | 精品久久久久久久人人人人传媒 | 国产成人在线视频 | 粉嫩国产精品一区二区在线观看 | 啪一啪在线视频 | 久久久久亚洲 | 欧美不卡一区 | 黄视频免费 | 毛片a级毛片免费播放100 | 美女131mm久久爽爽免费 | 国产精品久久久久久久久免费高清 | 欧美一二精品 | 超碰97免费在线 | 久久久精品一区 | 91精品国产91久久久久久 | 国产精品一二三区 | 亚洲精品久久久久久一区二区 | 亚洲免费久久久 | 久久99久久 | 一区二区片| av免费在线播放 | 久久精品国产亚洲 | 波多野结衣二区 | 日韩不卡一区二区三区 | 欧美性久久 | 中文字幕日韩欧美 | 精品99爱视频在线观看 | 久久精品中文字幕 | 最新中文字幕在线 | 欧美白人做受xxxx视频 | 91精品中文字幕一区二区三区 | 热99精品视频 | 蜜桃视频一区二区三区 | 日韩在线观看 | 亚洲精品9999 |