android - VideoView getDrawingCache 返回黑色

标签 android bitmap screenshot android-videoview

所以我正在尝试制作 VideoView 的屏幕截图。我认为最简单的方法是:

videoView.setDrawingCacheEnabled(true);

然后当我需要截图的时候:

Bitmap screenshot = videoView.getDrawingCache();

但由于某种原因,我每次返回的位图都是黑色的。有人对此有任何成功吗?我也试过:

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

但是再一次,这返回给我一张黑色图像。我可以看到 VideoView 几乎没有记录在 Android javadocs 中。有帮助吗?

最佳答案

来自 View#setDrawingCacheEnabled 的文档:

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 使用硬件加速运行并绕过缓存机制。良好的源潜水可能会有所启发。

编辑 - this post似乎清除了一些东西:

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 的子级)

关于android - VideoView getDrawingCache 返回黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5278707/

相关文章:

java - Android ListAdapter 启动@top

android - BottomNavigationView 与最后一项重叠

android - 在设备上创建 9 补丁图像

java - 关于Android中BitmapFactory.Options的问题

iphone - 使用 ui 动画捕获 uiwindow 屏幕截图 30 fps

python - 如何限制 selenium python 中的屏幕截图高度?

java - 使用安全标志在后台自定义 android 应用预览

android ORMLite 在数据库创建时填充表

android - 如何将 RealmResults 对象转换为 RealmList?

android - 在 Android 上保存自定义 View 的屏幕截图