当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Grab Frame/Screenshot from SurfaceView while Playing Video

问题描述:

Some video players like "ExoPlayer" are using SurfaceView as a listener to the VideoEngine. When doing a screenshot, I am just getting a black image.

Here's how I am creating the screenshot:

 public Bitmap viewToBMP(View view) {

view.setDrawingCacheEnabled(true);

Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());

view.setDrawingCacheEnabled(false);

return bitmap;

}

I've already searched intensively on SO, but there are no relevant answers, only workarounds. Is there a solution?

网友答案:

You can try to use View.draw(Canvas canvas). I am not sure if there are limitations related to the SurfaceView but I know a similar approach works for taking snapshots of WebViews.

public Bitmap getBitmapFromView(View view) {
    Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    view.draw(canvas);
    return bitmap;
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: