我的目标是拥有一个带有快照按钮(imgSnap)的自定义相机,当按下该按钮时,我希望应用程序转到另一个 Intent (CameraReview),其中图像显示在 ImageView 中,用户可以在此处选择保留或删除。下面的代码一直有效,直到我开始审查 Intent ,它只是在相机预览上暂停并中断。我找不到原因。
Button imgSnap = (Button)findViewById(R.id.imgSnap);
imgSnap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mCamera.takePicture(null, null, null, new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
Toast.makeText(getApplicationContext(), "Picture Taken",
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(x, CameraReview.class);
intent.putExtra("image_arr", data);
setResult(RESULT_OK, intent);
webView.startActivity(intent);
camera.stopPreview();
if (camera != null) {
camera.release();
mCamera = null;
}
finish();
}
});
}
});
编辑: 抛出以下异常:
Camera is being used after Camera.release() was called
最佳答案
您似乎有两个不同的相机实例。其中之一看起来与您的代码无关。
尝试改变
camera.stopPreview();
if (camera != null) {
camera.release();
mCamera = null;
}
至
mCamera.stopPreview();
if (mCamera != null) {
mCamera.release();
mCamera = null;
}
关于java - Android onPictureTaken 到 Intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32822854/