Take camera screenshot while recording - Like in Galaxy S3?

前端 未结 2 1768
臣服心动
臣服心动 2021-01-14 13:31

Im developing a camera app which uses SurfaceView for display.

I\'m able to take screenshot of the SurfaceView (and save it as a bitmap)
with getDrawingCache() (

2条回答
  •  佛祖请我去吃肉
    2021-01-14 13:57

    Well after hours, I got a nice solution for that.
    Maybe it isn't the best way, but it is good enough for me.

    private long start;
    private long end;
    private long period;
    

    First get a start time right after the media recorder starts:

    private void startRecording()
    {
       mMediaRecoder.start();
       start = System.currentTimeMillis();
    }
    

    Then, when u press on the screen/button for taking screenshot, save the period:

    private void captureImage()
    {
       end = System.currentTimeMillis();
       period = end - start;
    }
    

    Finally, when you stop recording, get the bitmap using the period and the Media retriever:

    private void saveVideo()
    {
       MediaMetadataRetriever retriever = new MediaMetadataRetriever();
       //path -> the path to the video
       retriever.setDataSource(path);
       Bitmap bitmap = retriever.getFrameAtTime(period * 1000,MediaMetadataRetriever.OPTION_CLOSEST);
    }
    

    Hope it helps you!

提交回复
热议问题