2013-07-23 58 views
1

使用Direct2D的,我想能夠要麼渲染到系統內存或渲染目標的內容複製到系統內存。複製從渲染目標主機內存

Direct2D可以嗎?或者我將不得不做一些d3d互操作?

+0

可能重複[如何從Direct2D的檢索像素數據(http://stackoverflow.com/questions/17513385/how-to-retrieve-pixel-data-from-direct2d) –

回答

1

您可以使用ID2D1Factory :: CreateWICBitmapRenderTarget呈現在WIC位圖,可以在像素從WIC位圖,然後讀取。沿着這些路線的東西:

ID2D1Factory* d2dfac = 0; 
D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &d2dfac); 

IWICImagingFactory* wicfac = 0; 
CoCreateInstance(CLSID_WICImagingFactory, 0, CLSCTX_INPROC_SERVER, 
      IID_IWICImagingFactory, (void**)&wicfac); 

IWICBitmap* bmp = 0; 
wicfac->CreateBitmap(width, height, 
         GUID_WICPixelFormat32bppPBGRA, 
         WICBitmapCacheOnLoad, &bmp); 

ID2D1RenderTarget* render = 0; 
d2dfac->CreateWicBitmapRenderTarget(
    bmp, 
    D2D1::RenderTargetProperties(D2D1_RENDER_TARGET_TYPE_DEFAULT, 
            D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, 
                D2D1_ALPHA_MODE_PREMULTIPLIED), 
            0.f, 0.f, 
            D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE), 
    &render); 

render->BeginDraw(); 
// ... Draw on the render target ... 
render->EndDraw(0, 0); 

WICRect rect = { 0, 0, width, height }; 
IWICBitmapLock* lock = 0; 
bmp->Lock(&rect, WICBitmapLockRead, &lock); 

BYTE* data = 0; 
UINT sz = 0; 
lock->GetDataPointer(&sz, &data);