【发布时间】:2025-12-08 09:55:02
【问题描述】:
我想将 ID2D1Effect 的输出图像转换为 ID2D1Bitmap,这样我就可以在以后绘制它,而无需一遍又一遍地应用所有效果...
我的第一次尝试只是保留 ID2D1Effect::GetOutput 图像 ptr,但如果我将效果与另一个图像源一起使用,此图像会发生变化...
我的下一个尝试是创建一个设置了 D2D1_BITMAP_OPTIONS_TARGET 标志的位图 (ID2D1DeviceContext::CreateBitmap) 并将效果输出绘制到该位图,但这似乎也不起作用...
绘制效果到给定的 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 的函数返回错误代码)
我做错了什么?
我该怎么做?
【问题讨论】:
-
要查找问题,启用 Direct2D(和 Direct3D)的调试层很有用。