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.
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.
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.