gpt4 book ai didi

android - VideoView getDrawingCache 返回黑色

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:02:06 29 4
gpt4 key购买 nike

所以我正在尝试制作 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com