我正在将自定义 CAD 软件从 GDI 转换为 Direct2D。我在平移绘图时遇到问题。我想做的是创建一个与绘图窗口一样宽 3 倍且高 3 倍的位图。然后,当用户开始平移时,我会渲染应该可见的位图部分。
麻烦的是,它看起来好像你的位图不能比你的渲染目标大。到目前为止,我所做的大致如下:
// Get the size of my drawing window.
RECT rect;
HDC hdc = GetDC(hwnd);
GetClipBox(hdc, &rect);
D2D1_SIZE_U size = D2D1::SizeU(
rect.right - rect.left,
rect.bottom - rect.top
);
// Now create the render target
ID2D1HwndRenderTarget *hwndRT = NULL;
hr = m_pD2DFactory->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties(hwnd, size),
&hwndRT
);
// And then the bitmap render target
ID2D1BitmapRenderTarget *bmpRT = NULL;
// We want it 3x as wide & 3x as high as the window
D2D1_SIZE_F size = D2D1::SizeF(
(rect.right - rect.left) * 3,
(rect.bottom - rect.top) * 3
);
hr = originalTarget->CreateCompatibleRenderTarget(
size,
&bmpRT
);
// Now I draw the geometry to my bitmap Render target...
// Then get the bitmap
ID2D1Bitmap* bmp = NULL;
bmpRT->GetBitmap(&bmp);
// From here I want to draw that bitmap on my hwndRenderTarget.
// Based on where my mouse was when I started panning, and where it is
// now, I can create a destination rectangle. It's the size of my
// drawing window
D2D1_RECT_U dest = D2D1::RectU(x1, y1, x1+size.width, y1+size.height);
hwndRT->DrawBitmap(
bmp,
NULL,
1.0,
D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
dest
);
因此,当我检查位图的大小时,它检查正常 - 这是我的位图渲染目标的大小,而不是我的 hwnd 渲染目标的大小。但是如果我将 x1 & y1 设置为 0,它应该绘制位图的左上角(这是屏幕外的一些几何图形)。但它只是绘制屏幕上的左上角。
有人对这个有经验么?如何创建一个相当大的位图,然后在较小的渲染目标上渲染它的一部分?由于我正在平移,因此每次鼠标移动都会进行渲染,因此它必须具有合理的性能。