首页 > 解决方案 > 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);
}
.
.

我的问题是将什么作为参数传递,因为当我尝试访问该方法时它会出错。(文件图像文件)

如果有人可以分析,我将不胜感激!

标签: javaandroidflutter

解决方案


推荐阅读