热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何防止或关闭位图的direct2d“自动缩放”?-Howtopreventorturnoffdirect2d“autoscaling”ofabitmap?

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 个解决方案

#1


1  

A render target could not be just automatically resized. In your case, you are changing the size of the window, but this doesn't cause a change of the "attached" render target size.

渲染目标无法自动调整大小。在您的情况下,您正在更改窗口的大小,但这不会导致更改“附加”渲染目标大小。

You should handle the resize event of your window and then you have two possibilities:

您应该处理窗口的resize事件,然后您有两种可能性:

  1. Recreate your render target with the new size.
  2. 使用新大小重新创建渲染目标。
  3. Use ID2D1HwndRenderTarget::Resize or IDXGISwapChain::ResizeBuffers
  4. 使用ID2D1HwndRenderTarget :: Resize或IDXGISwapChain :: ResizeBuffers

Additionally, you can check:

此外,您可以检查:

  • Resizing Render Target Direct2D after WM_SIZE
  • 在WM_SIZE之后调整渲染目标Direct2D的大小
  • Smooth window resizing in Windows (using Direct2D 1.1)?
  • 在Windows中调整平滑窗口大小(使用Direct2D 1.1)?

推荐阅读
author-avatar
mobiledu2502869617
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有