我正在尝试使用Camera2
Android
上的CaptureCallback
API将采集中的所有参数导出到texte文件中。我发现它们都包含在file
中,但我只是不知道如何解析它们并将它们写入private CameraCaptureSession.CaptureCallback mCaptureCallback = new CameraCaptureSession.CaptureCallback()
{
private void process(CaptureResult result)
{
//parse and write as txt all available result keys and values
}
}
。
this
这可能是一件容易的事。
答案 0 :(得分:0)
这是一段完成工作的代码。我打开一个文件,解析所有键并将值写入其中:
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "MyApp");
File outputfile = new File(mediaStorageDir, "Camera_parameters.txt");
if (! mediaStorageDir.exists()){
if (! mediaStorageDir.mkdirs()){
return;
}
}
try {
FileOutputStream m_outputstream = new FileOutputStream(outputfile);
OutputStreamWriter m_stream = new OutputStreamWriter(m_outputstream);
List<CaptureResult.Key<?>> keys = result.getKeys();
for (CaptureResult.Key<?> key : keys) {
Log.d(TAG, key + " has value " + result.get(key));
m_stream.write(key + "\t" + result.get(key) + "\n");
}
m_stream.close();
}
catch (IOException e)
{
Log.e("Exception", "File write failed: " + e.toString());
}