我正在使用camera2 API,但存在一些问题。再具体一点。这是从摄像机捕获的图像保存到某个位置的地方。 (按照代码,它应该保存到外部sdcard中)。但是将其保存到内部存储子文件夹“ keiko”。在外部sdcard中没有创建文件夹。
private static File getOutputMediaFile() {
File mediaStorageDir = new File(
Environment
.getExternalStorageDirectory(),
"keiko");
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d("keikoimages", "failed to create directory");
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(new Date());
mediaFile = new File(mediaStorageDir.getPath() + File.separator
+ "IMG_" + timeStamp + ".jpg");
imageName = "IMG_" + timeStamp + ".jpg";
filePath = mediaStorageDir.getPath()+ File.separator;
return mediaFile;
}
在onCaptureCompleted函数中,我试图将保存的图像显示到imageview。它停止相机,并在纹理视图中显示捕获的图像,但不在imageview(camview)中显示。
@Override
public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) {
super.onCaptureCompleted(session, request, result);
File sd = (Environment.getExternalStorageDirectory());
File image = new File(sd+"/keiko/", imageName);
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath());
Matrix matrix = new Matrix();
int width = bitmap.getWidth();
int height = bitmap.getHeight();
bitPicFinal = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
runOnUiThread(new Runnable() {
@Override
public void run() {
camview.setImageBitmap(bitPicFinal);
}
});
}
private void runOnUiThread(Runnable runnable) {
}
};
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
cameraDevice.close();
textureView.setOpaque(false);
return true;
}
需要帮助将保存的图像加载到imageview并关闭纹理视图。不知道,我的方向正确。请引导我。