gpt4 book ai didi

c++ - 使用 Direct2D 渲染位图的一部分

转载 作者:太空宇宙 更新时间:2023-11-04 14:20:55 25 4
gpt4 key购买 nike

我正在将自定义 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
);

所以当我检查我的位图大小时,它检查出 OK - 它是我的位图渲染目标的大小,而不是我的 hwnd 渲染目标。但是如果我将 x1 & y1 设置为 0,它应该绘制位图的左上角(这是屏幕上的一些几何图形)。但它只是绘制屏幕上 内容的左上角。

有没有人有这方面的经验?我怎样才能创建一个相当大的位图,然后在较小尺寸的渲染目标上渲染它的一部分?由于我在平移,渲染将在每次鼠标移动时进行,因此它必须具有合理的性能。

最佳答案

我不是 direct2d 专家 (direct3d),我在查看您的源代码和文档时发现您传递了 DrawBitmap 的第二个参数 - NULL,而不是提供位图的源矩形

    m_pRenderTarget->DrawBitmap(
m_pBitmap,
D2D1::RectF(
upperLeftCorner.x,
upperLeftCorner.y,
upperLeftCorner.x + scaledWidth,
upperLeftCorner.y + scaledHeight),
0.75,
D2D1_BITMAP_INTERPOLATION_MODE_LINEAR
);

我建议查看 here例如

关于c++ - 使用 Direct2D 渲染位图的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7759803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com