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. 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.
public void onClick() {
if(!onProgress)
mCamera.takePicture(null, mPictureCallback, mPictureCallback);
}
Camera.Pictur开发者_开发问答eCallback 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. 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.
精彩评论