我正在使用此Camera2Basic示例,但在使用它时遇到了问题,因为此Camera2Basic
在某些设备上无法像在特定设备 HUAWEI SHT-W09 上正常工作,拍照成功完成,但照片未保存!
这就是我捕获并获取文件的方式。
CameraBasic2Fragment
private void captureStillPicture() {
//... some stuff
CameraCaptureSession.CaptureCallback CaptureCallback
= new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session,
@NonNull CaptureRequest request,
@NonNull TotalCaptureResult result) {
//showToast("Saved: " + mFile);
Log.d(TAG, mFile.toString());
unlockFocus();
try {
closeCamera();
} finally {
getActivity().runOnUiThread(() -> mListener.onFilePathGenerated(mFile.toString()));
}
}
};
mCaptureSession.stopRepeating();
mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
}
MainActivity
@Override
public void onFilePathGenerated(String path) {
this.imagePath = path;
binding.layoutImage.setVisibility(View.VISIBLE);
Bitmap bitmap = BitmapFactory.decodeFile(path, Utils.bitMapOptions(path, 180, 180));
binding.ivProfilePhoto.setImageBitmap(bitmap);
getFragmentManager().beginTransaction().remove(getFragmentManager().findFragmentByTag("cameraFragment")).commit();
}
这是我的日志。
D/Camera2BasicFragment: /storage/emulated/0/Android/data/projectname/files/User_1554775675841.jpg
E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/Android/data/projectname/files/User_1554775675841.jpg (No such file or directory)
感谢您的帮助。谢谢。