我需要在屏幕外的位图上绘制形状,但是当我尝试渲染位图时出现了奇怪的问题。
这是图片应该显示的方式:
而这是我看到位图的方式:
以下是我用来创建位图画刷的代码:
const auto size = renderTarget->GetSize();
const auto pxSize = D2D1::SizeU(size.width * 4, size.height * 4);
ID2D1BitmapRenderTarget* compatibleRenderTarget;
HRESULT hr = renderTarget->CreateCompatibleRenderTarget(size, pxSize, &compatibleRenderTarget);
if (SUCCEEDED(hr))
{
// compute visible area and the current transformation matrix
const auto area = get_visible_area(renderTarget);
const auto transform = D2D1::Matrix3x2F::Identity();
// offscreen bitmap rendering
compatibleRenderTarget->BeginDraw();
// draw all shapes
compatibleRenderTarget->EndDraw();
// Retrieve the bitmap from the render target.
ID2D1Bitmap* bitmap;
hr = compatibleRenderTarget->GetBitmap(&bitmap);
// release the compatible render target
compatibleRenderTarget->Release();
// Create the bitmap brush
ID2D1BitmapBrush* bitmapBrush = nullptr;
hr = renderTarget->CreateBitmapBrush(bitmap, D2D1::BitmapBrushProperties(), &bitmapBrush);
bitmap->Release();
// draw bitmap
renderTarget->FillRectangle(area, bitmapBrush);
}