Question

i want to convert the output image of an ID2D1Effect to an ID2D1Bitmap, so I'm able to draw it at a later time without applying all the effects over and over...

My first try was just to keep the ID2D1Effect::GetOutput image ptr, but this image changes if I use the effect with another image source...

My next try was to create a Bitmap (ID2D1DeviceContext::CreateBitmap) with D2D1_BITMAP_OPTIONS_TARGET flag set and draw the effects output to this Bitmap but that doesn't seem to work either...

Draw effect to given 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;

Draw the bitmap at a later time : (preview)

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

(Same DeviceContext - no function that returns HRESULT returns an error code)

What am I doing wrong?

How am I supposed to do this?

Was it helpful?

Solution

simply forgot to specify the PixelFormat in CreateBitmap.

D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED)

works now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top