什么叫开始preVIEW()影像拍摄后最好的方法是什么? [英] What's the best way to call StartPreview() after an image is captured?

查看:180
本文介绍了什么叫开始preVIEW()影像拍摄后最好的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦调用了Camera.takePicture(),我的preVIEW将停止在该文档中描述的更新。什么是检测图像采集过程结束,并呼吁启动preVIEW的最佳方式(),使之重新开始更新?

Once a call is made to Camera.takePicture(), my preview will stop updating as described in the docs. What's the best way to detect that the image capture process is finished and call startPreview() to make it start updating again?

该呼叫不能放置在任何传递给takePicture的回调,根据文档,因为他们都应该已经返回之前,我调用它。

The call can't be placed in any of the callbacks passed to takePicture, according to the docs, as they should all have returned before I invoke it.

我目前最好的猜测是创建一个处理程序和发布延迟的Runnable将它从JPEG回调(或取其最最后定义的回调返回)。

My current best guess is to create a Handler and post a delayed Runnable to it from the JPEG callback (or whichever is the most last defined callback to return).

推荐答案

您应该从内AsyncTask的(或线程),然而AsyncTaks的是更容易的选择开始mCamera.takePicture。

You should start the mCamera.takePicture from within an AsyncTask (or a thread) however AsyncTaks's are the easier option.

有一个非常简单的实现(这当然可以被修改)是:

A really simple implementation (which of course can be modified) is to:

打电话来拍照的方法

/**
 * Execute the AsyncTask that will handle the preview of the captured photo.
 */
public void takePicture() {
    TakePictureTask takePictureTask = new TakePictureTask();
    takePictureTask.execute();
}

的AsyncTask的子类

/**
 * A pretty basic example of an AsyncTask that takes the photo and
 * then sleeps for a defined period of time before finishing. Upon
 * finishing, it will restart the preview - Camera.startPreview().
 */

private class TakePictureTask extends AsyncTask<Void, Void, Void> {

    @Override
    protected void onPostExecute(Void result) {
        // This returns the preview back to the live camera feed
        mCamera.startPreview();
    }

    @Override
    protected Void doInBackground(Void... params) {
        mCamera.takePicture(null, null, mPictureCallback);

        // Sleep for however long, you could store this in a variable and
        // have it updated by a menu item which the user selects.
        try {
            Thread.sleep(3000); // 3 second preview
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return null;
    }

}

的PictureCallback领域

private PictureCallback mPictureCallback = new PictureCallback() {

    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
        File file = null;

        // Check whether the media is mounted with read/write permission.
        if (Environment.MEDIA_MOUNTED.equals(
                Environment.getExternalStorageState())) {
            file = getOutputMediaFile();
        }

        if (file == null) {
            Log.d(TAG, "Error creating media file, check storage persmissions!");
            return;
        }

        try {
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            fileOutputStream.write(data);
            fileOutputStream.close();
        } catch (FileNotFoundException e) {
            Log.d(TAG, "File not found: " + e.getMessage());
        } catch (IOException e) {
            Log.d(TAG, "Error accessing file: " + e.getMessage());
        }
    }
};

这篇关于什么叫开始preVIEW()影像拍摄后最好的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆