作者:mobiledu2502869617 | 来源:互联网 | 2023-10-12 15:54
IhaveaproblemwithDirect2Dbitmapscaling.Iloadedabitmapfromafileusingthatexample,the
I have a problem with Direct2D bitmap scaling. I loaded a bitmap from a file using that example, then I wanted to scale bitmap by myself (fit to view saving proportions, add a shadow effect…) but Direct2D automatically scales bitmap (e.g. while resizing a window) and I do not know how to prevent this behavior.
我有Direct2D位图缩放问题。我使用该示例从文件加载了一个位图,然后我想自己缩放位图(适合查看保存比例,添加阴影效果......)但是Direct2D会自动缩放位图(例如在调整窗口大小时),我不知道如何防止这种行为。
For example, after bitmap loaded into a small window (CView) it fills the entire window correctly (according OnDraw) and when I maximize it D2D stretch my bitmap with losing bitmap quality and finally the bitmap greatly exceeds borders of the window despite my OnDraw method.
例如,在将位图加载到一个小窗口(CView)之后,它正确填充整个窗口(根据OnDraw),当我最大化它时,D2D拉伸我的位图失去位图质量,最后位图大大超出了窗口的边界,尽管我的OnDraw方法。
void CWDCView::OnDraw(CDC* /*pDC*/)
{
CWDCDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc) return;
HRESULT hr = S_OK;
ID2D1DeviceContext *deviceContext;
pRenderTarget->QueryInterface(&deviceContext); //ID2D1HwndRenderTarget* pRenderTarget
RECT rc = {0,0,0,0};
GetClientRect(&rc);
deviceContext->BeginDraw();
deviceContext->Clear( D2D1::ColorF( D2D1::ColorF(0xC8D2E1, 1.0f) ) );
D2D1_RECT_F rect={0,0,rc.right,rc.bottom};
deviceContext->DrawBitmap(m_pBitmap,rect); //ID2D1Bitmap *m_pBitmap
deviceContext->EndDraw();
if (hr == D2DERR_RECREATE_TARGET)
{
hr = S_OK;
ReleaseDeviceResources();
}
SafeRelease(&deviceContext);
}
So how to prevent or turn off this “autoscaling”?
那么如何防止或关闭这种“自动缩放”呢?
I want to add one thing. If draw bitmap like that deviceContext->DrawBitmap(m_pBitmap); /*without rect*/
it draws just a part of the bitmap without fitting it into the window but when maximizing it stretch it anyway.
我想补充一点。如果像那个deviceContext-> DrawBitmap(m_pBitmap)那样绘制位图; / *没有rect * /它只绘制位图的一部分而不将其装入窗口但是当最大化它时无论如何都要拉伸它。
1 个解决方案