简体   繁体   English

Android-双击相机

[英]Android - Camera with double click

Below are the important stuff. 以下是重要的内容。 The problem is: I have the camera take a picture when I tap on the surface and store the image to the SD card . 问题是:当我敲击表面时,我让相机拍照并将图像存储到SD卡中 If I click two or more times before the camera stores the picture, the camera freezes and the phone need a restart. 如果在相机存储照片之前单击两次或两次以上,相机将冻结,并且手机需要重新启动。 I think I have all the release stuff correct. 我想我所有发布的东西都正确。 I even implemented a boolean onProgress to take some action, but it seems it doesn't work. 我什至实现了一个布尔型onProgress来采取一些措施,但似乎不起作用。

public void onClick() {
    if(!onProgress)
    mCamera.takePicture(null, mPictureCallback, mPictureCallback);
}

Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
    public void onPictureTaken(byte[] imageData, Camera c) {
        onProgress=true;
        if (imageData != null) {
            Intent mIntent = new Intent();
            try {
                FileOutputStream out = new FileOutputStream(
                        "/sdcard/Deltio1.jpg");
                Bitmap e = BitmapFactory.decodeByteArray(imageData, 0,
                        imageData.length);
                e.compress(Bitmap.CompressFormat.JPEG, 65, out);
                out.close();
                Intent i = new Intent(ACT, MediaSend.class);
                ACT.startActivity(i);
            }
            catch (Exception e) {
                Toast
                .makeText(
                        CON,
                        "???ß??µa st?? ap????e?s?.?eßa???e?te ?t? ??ete sdcard e??atest?µ???",
                        Toast.LENGTH_LONG).show();
                ACT.finish();
            }

            // FileUtilities.StoreByteImage(mContext, imageData,
            // 50, "ImageName");

            SystemClock.sleep(2000);
            mCamera.startPreview();

            onProgress=false;

            // setResult(FOTO_MODE,mIntent);
            // finish();
        }
    }
};

You can refer to the entire code . 您可以参考整个代码

The problem is your onProgress flag. 问题是您的onProgress标志。 You should set it to true at 您应将其设置为true

public void onClick() {
        if(!onProgress){
                     **onProgress = true;** 
           mCamera.takePicture(null, mPictureCallback, mPictureCallback);
                  }

    }

Usually, there is a delay of atleast 300-500 milliseconds between the takePicture() and PictureCallback because Camera sensor has to: 1. Perform Autofocus operation 2. Stop the preview 3. Capture the preview data 4. Encode the raw data 5. AND Fianlly call PictureCallback method. 通常, takePicture()PictureCallback之间至少要延迟300-500毫秒,因为相机传感器必须:1.执行自动对焦操作2.停止预览3.捕获预览数据4.对原始数据进行编码5.和最后调用PictureCallback方法。

Regards, Anirudh. 问候,Anirudh。

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

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