问题描述:

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;
}
相关阅读:
Top