BitmapCache和RenderTargetBitmap [英] BitmapCache and RenderTargetBitmap

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

问题描述

下面的代码似乎没有利用位图缓存

------
uiElement有一个位图缓存


RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(
(int)uiElement.ActualWidth,(int)uiElement.ActualHeight,
96,96,
PixelFormats.Pbgra32
);


renderTargetBitmap.Render(uiElement); //仍然很慢

uint [] arrBits = new uint [renderTargetBitmap.PixelWidth * renderTargetBitmap.PixelHeight];
renderTargetBitmap.CopyPixels(arrBits,4 * renderTargetBitmap.PixelWidth,0); <不管怎样--------

无论有没有BitmapCache,我的性能都差不多。

有没有办法利用新的BitmapCache功能用于获取UIElement的像素数据?

The following code does not seem to take advantage of the bitmap cache

------
uiElement has a bitmap cache


RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(
                                                               (int)uiElement.ActualWidth, (int)uiElement.ActualHeight,
                                                               96, 96,
                                                               PixelFormats.Pbgra32
                                                               );

renderTargetBitmap.Render(uiElement);    // still very slow

uint[] arrBits = new uint[renderTargetBitmap.PixelWidth * renderTargetBitmap.PixelHeight];
renderTargetBitmap.CopyPixels(arrBits, 4 * renderTargetBitmap.PixelWidth, 0);
--------

I have more or less the same performance with and without BitmapCache.

Is there a way to take advantage of the new BitmapCache feature to get the pixel data of an UIElement ?

推荐答案

这里的答案是否定的。 BitmapCache API旨在缓存视频内存中的内容(在硬件中渲染时),这意味着它会驻留在GPU上。这样可以节省在将内容绘制到屏幕时重新呈现该内容的成本。 RenderTargetBitmap将您的软件内容呈现为系统内存中的缓冲区。事实上,RenderTargetBitmap是通过创建合成器和本机渲染堆栈的全新实例来实现的,因此使用RenderTargetBitmap时BitmapCache根本没有明显的效果。无法在硬件中呈现内容并将输出放在系统内存中的RenderTargetBitmap中。将位从视频内存拉回到系统内存是很昂贵的,因此我们没有提供任何方法来使用新的BitmapCache API执行您所要求的操作,但是对于将来的版本,这是一个很好的建议。
The answer here is no.  The BitmapCache API is designed to cache your content (when rendering in hardware) in video memory, meaning it stays resident on your GPU.  This saves you the cost of re-rendering that content when drawing it to the screen.  RenderTargetBitmap renders your content in software to a buffer in system memory.  In fact, RenderTargetBitmap is implemented by creating a whole new instance of the compositor and native rendering stack, so BitmapCache will have no appreciable effect at all when using RenderTargetBitmap.  There is no way to render your content in hardware and put the output in a RenderTargetBitmap in system memory.  It's expensive to pull bits back from video memory to system memory so we did not offer any way of doing what you're asking for with the new BitmapCache API, but the addition is a good suggestion for a future version.


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

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