本文介绍了安卓(相机​​) - 如何同步停止preVIEW()与onPictureTaken()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在客户端使用相机拍摄照片的应用程序。图像的preVIEW是使用SurfaceView示于片剂,前的人打我的点击按钮。当人撞击点击按钮,所述方法onPictureTaken被调用,并且,在该方法中,我保存的图像,并且也调用的camera.stop preVIEW()方法(因此,用户可以看到已采取的图片)

I have an app in which the client uses the camera to take a picture. The preview of the image is being shown in the tablet using a SurfaceView, before the person hits my "click" button. When the person hits the click button, the method onPictureTaken is called, and, in that method, I save the image and also call the camera.stopPreview() method (so the user can see the picture that was taken).

有一个问题,但是...如果用户在周围移动平板电脑的那一刻,该照片拍摄,静止画面实际显示的停止preVIEW方法被调用后不对应到一个我得到的onPictureTaken方法的字节数组中。有一些毫秒出现在其中做出不同的站出来当用户走动拍摄照片之前(我知道,99%的人不会移动的平板电脑左右,而拍摄照片的平板电脑的延迟,但我的客户实际上注意到了这个问题,并希望它固定...)。我试图移动了保存操作将一个separete螺纹,如下所示,这样onPictureTaken方法可以执行尽可能快。不过,它没有任何效果可言......

There is an issue, however... If the user is moving around the tablet at the moment that the picture is taken, the still picture actually shown after the stopPreview method is called DOES NOT correspond to the one that I get in the byte array of the onPictureTaken method. There is a delay of some miliseconds there in which make that difference to stand out when the user is moving around the tablet just before the picture is taken (I know that 99% of the people will not move the tablet around while taken the picture, but my client actually noticed this issue and want it fixed...). I have tried to move the save operation to a separete thread, as shown below, so the onPictureTaken method can execute as fast as possible. Still, it had no effect at all...

private PictureCallback pictureCallback = new PictureCallback() {

    public void onPictureTaken(byte[] data, Camera camera) {

        camera.stopPreview();
        reference = data;

        new PictureCallbackHeavy().execute();
    }
};

我也trield调用camera.stop preVIEW()就在我打电话的takePicture方法(而不是onPictureTaken()方法中)。但结果是相同的。

I have also trield to call camera.stopPreview() just BEFORE I call the takePicture method (and not inside the onPictureTaken() method). But the result is the same.

我能做些什么来同步停止preVIEW方法,这样我就可以准确显示拍摄的图像,那就是onPictureTaken()回调的字节数组中?

What can I do to sync the stopPreview method so I can show EXACTLY the image that was taken and that is in the byte array of the onPictureTaken() callback?

感谢你在前进! =)

推荐答案

不幸的是,你不能仅仅通过调用停止preVIEW()取得一个合理的良好preVIEW形象,因为那一刻的照片拍摄,并此刻onPictureTaken()被调用有可以通过相当长的一段时间,因为它的工作原理是这样的:

Unfortunately you can't acquire a reasonable good preview image just by calling stopPreview() because between the moment the picture is taken and the moment onPictureTaken() is called there can pass quite some time because it works like this:

  • 相机实际拍摄照片(这就是你想要什么,preVIEW)
  • onShutter()被调用
  • onPictureTaken(),用于对原始图像数据被称为(在某些设备)
  • onPictureTaken()的比例preVIEW图像被称为(在某些设备上)
  • onPictureTaken()为最后的COM pressed图像数据被称为(一个我们正在谈论这里)

所以,你必须在字节[]在onPictureTaken数据()回调转换成位图和映射位图到一个ImageView的,你应该定位上面的SurfaceView来显示依然preVIEW图像。在code可能会是这个样子:

So you have to convert the byte[] data in your onPictureTaken() callback into a Bitmap and map that Bitmap onto an ImageView that you should position above your SurfaceView to show the still preview image.The code will probably look something like this:

public void onPictureTaken(byte[] data, Camera camera) {
    camera.stopPreview();
    final Bitmap image = BitmapFactory.decodeByteArray(data, 0, data.length);
    surfaceView.setVisibility(SurfaceView.GONE);
    imageView.setVisibility(ImageView.VISIBLE);
    imageView.setImageBitmap(image);
    reference = data;
    new PictureCallbackHeavy().execute();
}

这篇关于安卓(相机​​) - 如何同步停止preVIEW()与onPictureTaken()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 05:47