在ID2D1Bitmap / Image中存储ID2D1Effect输出以便稍后绘制它?

时间:2014-03-21 18:32:47

标签: c++ effect direct2d

我想将ID2D1Effect的输出图像转换为ID2D1Bitmap,因此我可以在以后绘制它而不会反复应用所有效果......

我的第一次尝试只是为了保持ID2D1Effect :: GetOutput图像ptr,但如果我将效果与其他图像源一起使用,则此图像会发生变化...

我的下一个尝试是创建一个设置了D2D1_BITMAP_OPTIONS_TARGET标志的Bitmap(ID2D1DeviceContext :: CreateBitmap),并将效果输出绘制到此Bitmap,但这似乎不起作用......

将效果绘制到给定的Bitmap1 **(dest):

ComPtr<ID2D1Image> swapChainImageBuffer;
    this->pDeviceContext->CreateBitmap(D2D1::SizeU(120, 50), nullptr, 0, D2D1::BitmapProperties1(D2D1_BITMAP_OPTIONS_TARGET), dest);
    this->pDeviceContext->GetTarget(swapChainImageBuffer.GetAddressOf());
    this->pDeviceContext->SetTarget(*dest);
    this->pDeviceContext->BeginDraw();
    this->pDeviceContext->Clear(D2D1::ColorF(RGB(0, 0, 0), 1.f));
    this->pDeviceContext->DrawImage(this->pCompositeEffect.Get(), D2D1::Point2F(20, 10));    
    this->pDeviceContext->EndDraw();
    this->pDeviceContext->SetTarget(swapChainImageBuffer.Get());
    swapChainImageBuffer = nullptr;

稍后绘制位图:(预览)

this->pD2DeviceContext->DrawBitmap(preview.Get(), D2D1::RectF(x, y, x+width, y + height));

(相同的DeviceContext - 没有返回HRESULT的函数返回错误代码)

我做错了什么?

我该怎么做?

1 个答案:

答案 0 :(得分:0)

只是忘了在CreateBitmap中指定PixelFormat。

D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED)

现在有效。