VideoView getDrawingCache 返回黑色
所以我正在尝试制作 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);
但是,这又给我返回了黑色图像。我可以看到 Android javadoc 中几乎没有记录 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);
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 View#setDrawingCacheEnabled 的文档:
VideoView 可能通过硬件加速运行并绕过缓存机制。良好的源头潜水可能会带来一些启发。
编辑 - 此帖子似乎澄清了一些事情:
(VideoView是SurfaceView的子级)
From the docs for View#setDrawingCacheEnabled:
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:
(VideoView is a child of SurfaceView)
从 API 10 开始,您可以使用 MediaMetadataRetriever 在给定时间检索帧(以微秒为单位)。这是示例代码:
Since API 10, you can use MediaMetadataRetriever to retrieve a frame at given time (in micro seconds). Here is a sample code: