简体   繁体   English

相机对象上的setOneShotPreviewCallback(),预览图像的裁剪版本

[英]setOneShotPreviewCallback() on a Camera object, cropped version of the preview Image

I am developing a fairly process hungry application which I need to take an image and save it every time a button is pressed. 我正在开发一个处理过程非常繁琐的应用程序,每次按下按钮时,我都需要拍摄图像并将其保存。 On pressing the button I trigger the setOneShotPreviewCallback() method of the camera object to get a byte[] representing the image at that moment. 按下按钮后,我触发了相机对象的setOneShotPreviewCallback()方法,以获取此时表示图像的byte[] At the moment after this I take this byte[] and convert that to a bitmap using a YUVImage object which is very heavy on the processor. 此后的那一刻,我使用这个byte[]并使用YUVImage对象将其转换为位图,该对象在处理器上非常繁琐。 To reduce this I crop the image using: 为了减少这种情况,我使用以下方法裁剪图像:

Rect rect = new Rect(4*w/10, 0, 9*w/10, h);
final ByteArrayOutputStream output_stream = new ByteArrayOutputStream();
yuv_image.compressToJpeg(rect, 100, output_stream);

I would like to know if I can do this only using the byte[] and not have to convert it to the YUV Image? 我想知道是否只能使用byte[]来执行此byte[] ,而不必将其转换为YUV图像吗? like before the callback is triggered the Rect is created and the byte[] is only populated with the image data inside that Rect? 像在触发回调之前创建Rect并仅用Rect内部的图像数据填充byte[]吗?

尝试设置PreviewFormat:

parameters.setPreviewFormat(ImageFormat.JPEG);

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

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