VideoView getDrawingCache将返回黑 [英] VideoView getDrawingCache is returning black

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

问题描述

所以我试图做一个屏幕截图VideoView的。我想最简单的方法是:

So I'm trying to do a screen shot of a VideoView. I figured the easiest way would be:

videoView.setDrawingCacheEnabled(true);

后来,当我需要一个屏幕截图:

Then when I need to take a screenshot:

Bitmap screenshot = videoView.getDrawingCache();

但由于某些原因,我回来了位图​​只是黑色每次。任何人有任何这方面的成功?我也尝试过:

But for some reason the bitmap I get back is just black every time. Anyone had any success with this? I also tried:

Bitmap bitmap = Bitmap.createBitmap(videoView.getWidth(), videoView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
videoView.draw(canvas);

但再一次,这将返回我黑色的图像。我可以看到VideoView难以甚至记录在Android的javadoc。任何帮助?

But once again, this returns me a black image. I can see that the VideoView is hardly even documented in the Android javadocs. Any help?

推荐答案

从文档的<一个href="http://developer.android.com/reference/android/view/View.html#setDrawingCacheEnabled%28boolean%29">View#setDrawingCacheEnabled:

启用绘图缓存相似   要设置一层时,硬件   加速度是关闭的。什么时候   硬件加速被接通时,   使绘图缓存已经没有   渲染,因为该系统影响   使用不同的机制为   加速其忽略标志。   如果你想使用位图的   看来,即使硬件加速   启用后,看到setLayerType(INT,   android.graphics.Paint)为   如何让软件信息   和硬件层。

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. If you want to use a Bitmap for the view, even when hardware acceleration is enabled, see setLayerType(int, android.graphics.Paint) for information on how to enable software and hardware layers.

这有可能是VideoView工作在硬件加速,并绕过缓存机制。一个很好的来源下潜可能提供一些线索。

It's possible that the VideoView operates with hardware acceleration and is bypassing the caching mechanism. A good source dive might shed some light.

修改 - 这个帖子似乎明确一些事情:

Edit - this post seems to clear some things up:

对不起,它的性质SurfaceView呢   在普通视图层次不画   更新系统,所以它不会被绘制在   这一点。

Sorry, by its nature a SurfaceView does not draw in the normal view hierarchy update system, so it won't be drawn in that.

(VideoView是SurfaceView的孩子)

(VideoView is a child of SurfaceView)

这篇关于VideoView getDrawingCache将返回黑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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