使用 Direct2D 的大图像 [英] Large images with Direct2D

查看:29
本文介绍了使用 Direct2D 的大图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在为 Windows Store 开发应用程序,该应用程序使用 Direct2D 进行实时图像处理.它必须支持各种尺寸的图像.我遇到的第一个问题是如何处理图像大于支持的最大纹理大小的情况.经过一些研究和文档阅读后,我发现 VirtualSurfaceImageSource 作为解决方案.想法是将图像加载为 IWICBitmap,然后使用 CreateWICBitmapRenderTarget 创建渲染目标(据我所知,它不是硬件加速的).在一些绘图操作之后,我想通过使 VirtualSurfaceImage 源中的相应区域无效或在 NeedUpdate 回调触发时将结果显示到屏幕上.我认为可以通过创建 ID2D1Bitmap(硬件加速)并使用使用 CreateWICBitmapRenderTarget 创建的渲染目标和无效区域作为边界来调用 CopyFromRenderTarget,但该方法会返回 D2DERR_WRONG_RESOURCE_DOMAIN 作为结果.使用 IWICBitmap 的另一个原因是应用程序中涉及的算法之一必须有权更新图像的像素.

Currently I am developing application for the Windows Store which does real time-image processing using Direct2D. It must support various sizes of images. The first problem I have faced is how to handle the situations when the image is larger than the maximum supported texture size. After some research and documentation reading I found the VirtualSurfaceImageSource as a solution. The idea was to load the image as IWICBitmap then to create render target with CreateWICBitmapRenderTarget (which as far as I know is not hardware accelerated). After some drawing operations I wanted to display the result to the screen by invalidating the corresponding region in the VirtualSurfaceImage source or when the NeedUpdate callback fires. I supposed that it is possible to do it by creating ID2D1Bitmap (hardware accelerated) and to call CopyFromRenderTarget with the render target created with CreateWICBitmapRenderTarget and the invalidated region as bounds, but the method returns D2DERR_WRONG_RESOURCE_DOMAIN as a result. Another reason for using IWICBitmap is one of the algorithms involved in the application which must have access to update the pixels of the image.

问题是为什么这个逻辑不起作用?这是使用 Direct2D 实现我的目标的正确方法吗?此外,如果我想在 GPU 上使用大于最大允许纹理大小的图像进行图像处理,那么使用 CreateWICBitmapRenderTarget 创建的渲染目标不是硬件加速的,这是最佳解决方案吗?

The question is why this logic doesn't work? Is this the right way to achieve my goal using Direct2D? Also as far as the render target created with CreateWICBitmapRenderTarget is not hardware accelerated if I want to do my image processing on the GPU with images larger than the maximum allowed texture size which is the best solution?

提前谢谢你.

推荐答案

你说得对,大于纹理限制的图像必须在软件中处理.

You are correct that images larger than the texture limit must be handled in software.

但是,要问的问题是每次渲染时是否需要整个图像.

However, the question to ask is whether or not you need that entire image every time you render.

您可以使用硬件加速来渲染加载到软件目标中的大图像的一部分.

You can use the hardware accel to render a portion of the large image that is loaded in a software target.

例如,

  • 使用 ID2D1RenderTarget::CreateSharedBitmap 制作可供不同资源使用的位图.
  • 然后创建一个 ID2D1BitmapRenderTarget 并将大位图渲染到其中.(确保执行 BeginDraw、Clear、DrawBitmap、EndDraw).位图和渲染目标都可以被缓存以供后续调用使用.
  • 然后使用 ID2D1Bitmap::CopyFromRenderTarget 方法从该渲染目标复制到常规 ID2D1Bitmap 中,该部分将适合纹理内存.
  • 最后将它绘制到真正的渲染目标上,pRT->DrawBitmap

这篇关于使用 Direct2D 的大图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆