android - 如何在相机上获取捕获图像的 RealPath
问题描述
我想获取 imageview realPath 并编写 textview .. 我可以在库中获取 RealPath 但我不能在相机中
这是我的代码
此代码为库提供路径
private void takeLibrary(int sdk, String uriPath,String realPath){
this.txtSDK.setText("Build.VERSION.SDK_INT: "+sdk);
this.txtUriPath.setText("URI Path: "+uriPath);
this.txtRealPath.setText(realPath);
Uri uriFromPath = Uri.fromFile(new File(realPath));
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uriFromPath));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
imageView.setImageBitmap(bitmap);
}
还有这台相机
private void onCaptureImageResult(Intent data) {
// ????????????
}
?? 我应该写什么请帮助谢谢
解决方案
之后,试试这个:
private void onCaptureImageResult(Intent data) {
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
File destination = new File(Environment.getExternalStorageDirectory(),
System.currentTimeMillis() + ".jpg");
FileOutputStream fo;
try {
destination.createNewFile();
fo = new FileOutputStream(destination);
fo.write(bytes.toByteArray());
fo.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
ivImage.setImageBitmap(thumbnail);
}
推荐阅读
- java - Quarkus Reactive Postgresql 多个查询
- typescript - 错误代码 16 和错误代码 14,带有调度云功能
- javascript - 使用 EJS 和 Node 动态渲染具有函数的 HTML div
- typescript - 如何在 TypeScript 的类原型中实现迭代器?
- c - STM32 ADC(双同时)扫描模式功能影响采样率?
- javascript - 为什么 Number() 方法会在数字长度大于 15 时增加数字的值?
- c++ - 将 Parquet 文件读入 C++ 结构数组
- plsql - 如何使用shell函数修改表中一行的每个值?
- java - 无法使用捆绑将数据从活动发送到片段
- javascript - 函数将未定义传递给 Google Apps 脚本中的被调用函数