运行时错误,但一步一步的调试工作正常
问题描述:
我写了一个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
有人可以提出任何建议吗?预先感谢您
答
为您工作吗?
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);
它不起作用。没有照片被拍摄并保存在SD卡上。并且相机的预览模式也开始了。 – hanqiang
雅我无法确定当我张贴,如果这确实显示预览,我想是的。我知道这段代码适用于拍摄照片(在手机和模拟器上经过测试和正在运行的实现),所以也许还有别的事情正在为你做。你使用模拟器还是实际设备? –
我使用我的HTC感觉。 – hanqiang