我写了一个Android程序来拍照但没有预览。当我逐步调试它时,我的程序工作正常。但是,当我在执行模式下运行它时,程序无法按预期工作。没有图片保存,程序无法完成。此外,我不能在其他Android应用程序中使用我的相机(例如相机,摄像机),除非我重新启动手机。有人对这个问题有任何想法吗?拍照和记录错误的代码如下:
拍照代码:
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();
}
回调函数
Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] imageData, Camera c) {
if (imageData != null) {
StoreByteImage(mContext, imageData, 50,
"ImageName");
finish();
}
}
};
}
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
任何人都可以提出任何建议吗?提前谢谢
答案 0 :(得分:0)
这对你有用吗?
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);