本文介绍了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);

然后当我需要截图时:

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 javadocs 中.有什么帮助吗?

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?

推荐答案

来自 查看#setDrawingCacheEnabled:

启用绘图缓存类似硬件设置层加速关闭.什么时候硬件加速开启,启用绘图缓存没有对渲染的影响,因为系统使用不同的机制忽略标志的加速.如果你想使用位图查看,即使当硬件加速已启用,请参阅 setLayerType(int,android.graphics.Paint) 用于有关如何启用软件的信息和硬件层.

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 就其性质而言不在普通视图层次结构中绘制更新系统,所以它不会被拉进来

(VideoView 是 SurfaceView 的孩子)

(VideoView is a child of SurfaceView)

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

09-15 12:32