库 Java 无法在 Android Studio 3.1 中解析 [英] Library Java can't resolve in Android Studio 3.1

查看:31
本文介绍了库 Java 无法在 Android Studio 3.1 中解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的需要帮助,因为我尝试搜索其他论坛和其他关于 javax.imageio.ImageIO 和 java.awt.image.BufferedImage 的相同答案无法在 android studio 3.1 中解决.建议说我必须使用替代功能,但我找不到它.我需要的功能是

I really need help because I try search other forum and other problem same answer regarding to javax.imageio.ImageIO and java.awt.image.BufferedImage cannot be resolved in android studio 3.1. Suggestion say that I have to use alternative function but I couldn't find it. The function that I need is that

BufferedImage bufferedImage = ImageIO.read(file)

完整代码如下;

Uri selectedImage = data.getData();
        File auxFile = new File(selectedImage.toString());

        try {
            BufferedImage bufferedImage = ImageIO.read(auxFile);
            LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
            BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
            Result resultTxt = new MultiFormatReader().decode(bitmap);

            Toast.makeText(this, "result:"+resultTxt.getText(), Toast.LENGTH_LONG).show();

        }catch (IOException e){

        }catch (NotFoundException e) {
            e.printStackTrace();
        }

我真的很感谢那些能帮助我的人.

I really appreciated those who can help me.

推荐答案

javax.imageio.ImageIO 和 java.awt.image.BufferedImage 包在 android 上不可用.您应该改用位图.要从文件中读取位图,您应该这样做.

The packages javax.imageio.ImageIO and java.awt.image.BufferedImage are not available on android.You should use Bitmaps instead. To read a bitmap from a file you should do this instead.

BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(photoPath, options);

这篇关于库 Java 无法在 Android Studio 3.1 中解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆