简体   繁体   English

将视频视图转换为位图android

[英]convert video view to bitmap android

I am trying to convert a videoview into bitmap. 我正在尝试将videoview转换为位图。 Here's the code I have tried.But here the bitmap is always null. 这是我尝试过的代码,但是这里的位图始终为null。 Can anyone please tell me why and what is the correct way to do so. 谁能告诉我为什么以及这样做的正确方法是什么。

        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();

}

Consider using a TextureView instead of VideoView since it has getBitmap() method. 考虑使用TextureView而不是VideoView因为它具有getBitmap()方法。

More information here (android get screenshot of current videoview) . 此处有更多信息(android获取当前videoview的屏幕截图)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM