tags:

views:

67

answers:

1

I have the entire code here . 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 sdcard.If i click 2 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 seams it doesn't work. Any help would be .. you know... helpfull :P Thank you

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,
                        "Πρόβλημα στην αποθήκευση.Βεβαιωθείτε ότι έχετε sdcard εγκατεστημένη",
                        Toast.LENGTH_LONG).show();
                ACT.finish();
            }

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

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

            onProgress=false;



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

        }
    }
};
+1  A: 

The problem is your onProgress flag. You should set it to true at

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.

Regards, Anirudh.

aniait
didn't know that. Thank you it worked.Also do you know any sample code with camera flash and autofocus?
weakwire
There's an autofocus code in the API Demos itself. Usually, flash support varies from device to device as the sensor and the chipset have to support it. I think its a bit difficult to get hold of that code.
aniait