高效"屏幕截图"的景色? [英] Efficient "Screenshots" of a View?

查看:136
本文介绍了高效"屏幕截图"的景色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR:由于 getDrawingCache()似乎触发的查看时,硬件加速是一个完整的重绘启用后,有没有得到一个位图(或类似的规定),避免这一点,也许通过阅读填充到(硬件,软件),数据层的替代手段时, 查看最后得出?

TL;DR: Since getDrawingCache() seems to trigger a complete redraw of a View when hardware acceleration is enabled, is there an alternative means of getting a Bitmap (or something along those lines) that avoids this, perhaps by reading data populated into a (hardware, software) layer when the View was last drawn?

一些背景资料:

机器人已镜像屏幕由于Android 3.0,如到所连接的HDMI显示的能力。这可以用来为presentations,但它意味着观众看到了同样的事情presenter,这并不总是理想的。

Android has had the ability to mirror the screen since Android 3.0, such as to an attached HDMI display. This can be used for presentations, but it means the audience sees the same thing as the presenter, which is not always ideal.

的Andr​​oid 4.2加入 presentation ,允许应用程序把任意东西第二屏幕(如HDMI连接的显示器)上。在这种情况下,在倍,它也用于第二屏幕被示出是有用的的什么是主要的平板显示器上的部分的。如果你觉得presentation软件如Microsoft PowerPoint,LibreOffice的林preSS等,在典型的双屏幕设置中,观众看到当前presentation幻灯片,而presenter看到当前幻灯片和一个计时器和扬声器笔记和...

Android 4.2 added Presentation, to allow apps to put arbitrary stuff on the "second screen" (e.g., HDMI attached display). In this case, at times, it would be useful for the second screen to be showing part of what is on the main tablet's display. If you think of presentation software like Microsoft PowerPoint, LibreOffice Impress, and the like, in typical dual-screen setups, the audience sees the current presentation slide, while the presenter sees the current slide and a timer and speaker notes and...

对于非交互式内容,如PNG重新presenting幻灯片,这简直就是显示相同的图像在两个屏幕(与其他东西的主屏幕上)的问题。

For non-interactive content, like a PNG representing a slide, this is simply a matter of showing the same image in both screens (alongside other stuff on the primary screen).

然而,对于交互式内容,像 web视图,有时很难做到这一点的排序镜像。例如,我们知道当一个的WebView的含量可能会改变,因为它可以这样做的基础上的东西纯粹是在的WebView的没有什么好办法本身(如AJAX完成调用),我们分别做不是。而且,即使我们的没有的知道什么时候的WebView 的内容改变了,我们得到了一些其他的没有什么好办法的WebView 来呈现相同的内容。

However, for interactive content, like a WebView, it is sometimes difficult to do this sort of mirroring. For example, we have no good way of knowing when the content of a WebView might change, as it may do so based on stuff purely within the WebView itself (e.g., completion of AJAX calls), not something we do separately. And, even if we did know when the content of the WebView changed, we have no good way of getting some other WebView to render that same content.

所以,我想我会尝试建立一个 MirroringFrameLayout ,将使用 getDrawingCache()检索一个位图的容器中的内容,并交付给别人谁可以使其在屏幕上(例如,一个的ImageView 显示在 presentation )。

So I figured I'd try to set up a MirroringFrameLayout, that would use getDrawingCache() to retrieve a Bitmap of the container's contents and deliver that to somebody who can render it on-screen (e.g., an ImageView shown in a Presentation).

然而,启用硬件加速, setDrawingCacheEnabled(真) <一个href="http://developer.android.com/reference/android/view/View.html#setDrawingCacheEnabled%28boolean%29">is有点空操作的:

However, with hardware acceleration enabled, setDrawingCacheEnabled(true) is somewhat of a no-op:

启用附图缓存类似于设置一层硬件加速时关闭。硬件加速时接通,从而使拉丝缓存有渲染,因为该系统使用了不同的机构,用于加速该忽略标志没有任何影响。

Enabling the drawing cache is similar to setting a layer when hardware acceleration is turned off. When hardware acceleration is turned on, enabling the drawing cache has no effect on rendering because the system uses a different mechanism for acceleration which ignores the flag.

调用 getDrawingCache()在这些情况下,强制全画()查看为位图支持画布,而不是实际使用缓存。由于画()可能是昂贵的,做画()频繁(比如,通过触发postOnAnimation())的结果JANK。

Calling getDrawingCache() in these cases forces a full draw() of the View to a bitmap-backed Canvas, rather than actually using a cache. Since draw() may be expensive, doing draw() frequently (say, triggered via postOnAnimation()) results in jank.

因此​​,我想,以确定是否有其他绘图缓存,超越 getDrawingCache(),我们就可以使用硬件加速启用,这可能是用于设置这个镜像,这是更有效的。从我所看到的,有没有这样的缓存,作为层有效地写只能从SDK应用程序的角度来看。但是,我希望,也许我错过了一些解决方案。

Hence, I am trying to determine if there is some other "drawing cache", beyond getDrawingCache(), that we can use with hardware acceleration enabled, that could be used to set up this mirroring, and that is more efficient. From what I can see, there is no such cache, as layers are effectively write-only from the standpoint of SDK apps. However, I am hoping that perhaps I am missing some solution.

在此先感谢!

推荐答案

您可以使用 setLayerType(View.LAYER_TYPE_SOFTWARE,空),但它会做的副作用该视图慢重绘每次更新的时间。这将是更有效的创建自定义的的ViewGroup 绘制你的视图上的两个画布(每个画面。)您也可以简单地使用 ViewTreeObserver 和每一个取水回调迫使你的观点来呈现的第二屏幕上。我真的建议你不要试图滥用绘图缓存/层类型,这样的用例。

You can use setLayerType(View.LAYER_TYPE_SOFTWARE, null) but it will have the side effect of making that View slower to redraw every time it updates. It would be much more efficient to create a custom ViewGroup that draws your View on two Canvas (one for each screen.) You could also simply use a ViewTreeObserver and on every draw callback force your view to render on the second screen. I really recommend you don't try to abuse the drawing cache/layer type for such a use case.

这篇关于高效&QUOT;屏幕截图&QUOT;的景色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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