拿相机的屏幕截图,同时记录 - 银河S3样?银河、截图、屏幕、相机

2023-09-06 16:41:23 作者:我要、发光~

林开发相机应用,它使用SurfaceView显示。

Im developing a camera app which uses SurfaceView for display.

我能够采取SurfaceView的截图(并将其保存为位图) 与getDrawingCache()(在版面包装了SurfaceView) 并且还与canvas.drawBitmap(...)

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.

我有银河S3,我可以看到他们有这个功能在他们的相机 他们究竟如何做到的呢?

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

谢谢!

推荐答案

嗯小时后,我得到了一个很好的解决方案。照片 也许这是不是最好的方式,但它是很好的足够了。

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

然后,当u屏幕/按钮采取截图preSS,保存期:

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!