Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Take camera screenshot while recording - Like in Galaxy S3?

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() (on a layout which wraps the SurfaceView)
and also with canvas.drawBitmap(...)

however in both ways, the bitmap is always transparent/blank.

I have galaxy S3 and I can see that they have that feature in their camera how exactly they do it?

thanks!

like image 803
dor506 Avatar asked Dec 29 '25 22:12

dor506


1 Answers

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!

like image 165
dor506 Avatar answered Jan 01 '26 12:01

dor506



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!