java - java - 如何访问从java中的另一个类接收File作为参数的方法?
问题描述
朋友们,我有一个方法负责获取相机图像。在方法中,我转换为base64。
方法是这样的:
类:PhotoActivity.class
@Override
public String onImageCapture(File imageFile) {
// Convert file to bitmap.
// Do something.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath(), options);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
//Display the image to the image view
((ImageView) findViewById(R.id.cam_prev)).setImageBitmap(bitmap);
return encoded;
}
在MainActivity.java类中,我尝试像这样访问此方法:
.
PhotoActivity photo= new PhotoActivity();
.
.
if(call.method.equals("onImageCapture"))
{
photo.onImageCapture(//Difficulty understanding what I insert in the argument);
}
.
.
我的问题是将什么作为参数传递,因为当我尝试访问该方法时它会出错。(文件图像文件)
如果有人可以分析,我将不胜感激!
解决方案
推荐阅读
- javascript - 从命令行运行基于 DOM 的 Javascript
- javascript - 在 jQuery UI 模式对话框上锁定 Kendo UI DropDownTree 过滤器
- build - 如何使用“-fPIC”标志重新编译 ntl 和 gmp 库并将 HELib 设为共享库以及对 func(std::ostream&) 错误的未定义引用
- java - 硬件和操作系统对 Maven 构建速度的影响
- python - python中是否有类似的功能,例如带有重试选项的robocopy?
- mysql - MySQL - 计算未清项目并从不同表中获取日期
- javascript - 如何修复删除下拉框中的元素(Materialize)
- powerbi - 希望在同一行中获取对两个单独问题有答案的实体的 ID 计数 - Power BI
- c# - 为 Unity 编写 FPS 限制器
- excel - 如何用 i=1 到 12 的循环重写这个子,而 'txt_Case_Number(i).Text' 有一个值?