0
我有這樣一段代碼(只是用於試驗):保存拍攝的圖像
public void captureFromCam(View v) throws CameraAccessException {
try {
cm.openCamera("0", new CameraDevice.StateCallback(){
@Override
public void onClosed(CameraDevice camera) {
super.onClosed(camera);
}
@Override
public void onError(CameraDevice camera, int error) {
}
@Override
public void onOpened(final CameraDevice cam) {
Log.d("CameraApp", "Camera Opened");
ImageReader ir = ImageReader.newInstance(800, 600, 256, 1);
Surface surface = ir.getSurface();
final ArrayList<Surface> l = new ArrayList();
l.add(surface);
try {
cam.createCaptureSession(l, new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(CameraCaptureSession session) {
Log.e("CameraApp", "Configured");
CaptureRequest.Builder builder = null, b2;
try {
builder = cam.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
} catch (CameraAccessException e) {
e.printStackTrace();
}
builder.addTarget(l.get(0));
CaptureRequest request = builder.build();
try {
session.capture(request, new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) {
Log.e("CameraApp", "Captured");
}
}, null);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
@Override
public void onConfigureFailed(CameraCaptureSession session) {
}
}, null);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
@Override
public void onDisconnected(CameraDevice camera) {
}
}, null);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
有趣的是onCaptureCompleted
,我瞭解的結果是不知我的照片。
如何將此圖片保存到文件?或者如果它不是我的照片,我的照片在哪裏以及如何將它保存到文件?
我知道這個問題已被回答,但這是API 21,它與舊的很不同。