简体   繁体   English

Android Camera Preview屏幕截图

[英]Android Camera Preview Screenshot

I have implemented a custom camera using the Android docs. 我已经使用Android文档实现了自定义相机。 Everything works well and I use the cameras takePicture() method along with callbacks and all works fine. 一切正常,我使用相机的takePicture()方法以及回调,一切正常。 I found that it takes around 0-2 seconds for the callback to finish so I was wondering if there was any way to take a screenshot of the surfaceview contents after stopping the preview? 我发现回调完成大约需要0-2秒,因此我想知道是否有任何方法可以在停止预览后对Surfaceview内容进行屏幕截图? I have looked around and it doesn't seem to be possible. 我环顾四周,似乎不可能。 I tried implementing a GLSurfaceView but didn't have any luck. 我尝试实现GLSurfaceView,但没有任何运气。 Any feedback would be greatly appreciated, thanks! 任何反馈将不胜感激,谢谢!

If have facing some delays in my custom camera app when taking picture, the problem was saving the bitmap. 如果拍照时在我的自定义相机应用程序中遇到一些延迟,则问题在于保存位图。

takedPictureBitmap.compress(Bitmap.CompressFormat.PNG, 90, fOut); // saving the Bitmap to a path compressed as a PNG with 90% compression rate

Was delaying for 6 seconds until i see the preview again. 延迟了6秒,直到我再次看到预览。 I found that i'm requesting camera with JPEG format, so when the picture is taked, compressing the image to different format was taking to long. 我发现我要求使用JPEG格式的相机,因此在拍摄照片时,将图像压缩为其他格式会花费很长时间。 So i change compress to : 所以我将compress更改为:

takedPictureBitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut); // saving the Bitmap to a path compressed as a JPEG with 85% compression rate

And I saw the preview instantly :) 我立刻看到了预览:)

I hope it help!! 希望对您有所帮助!!

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

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