I wrote an android program to take a picture without preview. My programs works fine when I debug it step by step. However, when I run it in execution mode, the program doesn't work as expected. No picture is saved and the program can not finish. In addition, I can not use my camera in other android applications(e.g. Camera, Camcorder) unless I restart my phone. Anybody have any ideas about this problem? The code for taking pictures and the logged errors is as follows:
Code for taking pictures:
SurfaceView view = new SurfaceView(this);
mCamera = Camera.open();
Camera.Parameters p = mCamera.getParameters();
p.setPictureFormat(PixelFormat.JPEG);
mCamera.setParameters(p);
try {
mCamera.setPreviewDisplay(view.getHolder());
mCamera.startPreview();
mCamera.takePicture(null, null, mPictureCallback);
mCamera.stopPreview();
mCamera.unlock();
mCamera.release();
} catch (Exception e) {
mCamera.stopPreview();
mCamera.release();
e.printStackTrace();
}
The callback function
Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] imageData, Camera c) {
if (imageData != null) {
StoreByteImage(mContext, imageData, 50,
"ImageName");
finish();
}
}
};
}
The reported errors by logcat:
ERROR/Adreno200-ES20(130): rb verson is SBA #24
ERROR/mm-camera(130): prepare snapshot: Aec not settle
ERROR/CameraService(130): mHardware->setOverlay() failed with status -2147483648
ERROR/mm-camera(130): camera_issue_command: get_picture error (Connection timed out): length 36, status 0 FD: 20 1
ERROR/QualcommCameraHardware3D开发者_高级运维(130): getPicture: CAMERA_OPS_GET_PICTURE ioctl failed!
ERROR/NotificationService(292): adbEnabled = false
ERROR/NotificationService(292): adbEnabled = true
Can anybody give any suggestion? Thank you in advance
does this work for you?
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(),
currentTimeString + ".jpg");
outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PICTURE);
精彩评论