我试图让Flutter使用CameraX来使用In-Memory Buffer拍照,而不是保存到磁盘。
在CameraX ImageCapture.Java中,我找到了此代码段
// Wrap the ImageCapture.OnImageSavedListener with an OnImageCapturedListener so it can
// be put into the capture request queue
OnImageCapturedListener imageCaptureCallbackWrapper =
new OnImageCapturedListener() {
@Override
public void onCaptureSuccess(ImageProxy image, int rotationDegrees) {
Handler completionHandler = (mHandler != null) ? mHandler : mMainHandler;
CameraXExecutors.ioExecutor()
.execute(
new ImageSaver(
image,
saveLocation,
rotationDegrees,
metadata.isReversedHorizontal,
metadata.isReversedVertical,
metadata.location,
imageSavedListenerWrapper,
completionHandler));
}
@Override
public void onError(
UseCaseError error, String message, @Nullable Throwable cause) {
imageSavedListener.onError(error, message, cause);
}
};
该示例与Camera Preview有关
如何在CameraX Core中将Intent与内存缓冲区图像一起使用?
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
=> change to
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, InMemoryBuffer);
startActivityForResult(takePictureIntent, REQUEST_TAKE_IMAGE);
谢谢