1

使用 Direct2D,我希望能够渲染到系统内存或将渲染目标的内容复制到系统内存。

Direct2D有可能吗?还是我必须做一些 d3d 互操作?

4

1 回答 1

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 );
于 2013-07-23T08:37:11.017 回答