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

查看:51
本文介绍了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) 用于有关如何启用软件的信息和硬件层.

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天全站免登陆