将视频视图转换为位图android

时间:2016-10-17 18:45:33

标签: android bitmap android-videoview

我正在尝试将视频转换为位图。这是我尝试过的代码。但这里的位图始终为空。任何人都可以告诉我为什么以及这样做的正确方法。

        public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mainLayout = (RelativeLayout) findViewById(R.id.activity_main);

    videoView = new CustomVideoView(this);

    MediaController mediaController = new MediaController(getApplicationContext());
    mediaController.setAnchorView(videoView);
    videoView.setMediaController(mediaController);

    video_relativeLayout = new RelativeLayout(this);
    RelativeLayout.LayoutParams videoRelativeLayout_param = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT,
            RelativeLayout.LayoutParams.MATCH_PARENT);
    video_relativeLayout.setLayoutParams(videoRelativeLayout_param);

    videoView.requestFocus();
    video_relativeLayout.addView(videoView);


    videoView.setVideoURI(Uri.parse("android.resource://" + getApplicationContext().getPackageName() + "/" + R.raw.kitkat));

    videoView.requestFocus();
    videoView.start();

mainLayout.addView(video_relativeLayout);

    mainLayout.setDrawingCacheEnabled(true);
    mainLayout.buildDrawingCache();
    Bitmap bm = mainLayout.getDrawingCache();

}

1 个答案:

答案 0 :(得分:0)

考虑使用TextureView代替VideoView,因为它有getBitmap()方法。

更多信息here (android get screenshot of current videoview)