【问题标题】:Library Java can't resolve in Android Studio 3.1库 Java 无法在 Android Studio 3.1 中解析
【发布时间】:2018-06-19 10:13:46
【问题描述】:

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

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();
        }

我真的很感谢那些可以帮助我的人。

【问题讨论】:

  • 为什么对我的问题投反对票?这确实是需要按照指南提出的问题。

标签: android android-studio


【解决方案1】:

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

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

【讨论】:

  • 谢谢您的回复。实际上,他们在 zxing 库中使用了这些代码 LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage); BinaryBitmap 位图 = new BinaryBitmap(new HybridBinarizer(source));结果 resultTxt = new MultiFormatReader().decode(bitmap);
  • 那么我在哪里可以获得缓冲图像而不是位图。这个库扫描文件图像二维码而不是从相机扫描图像背后的原因。任何进一步的解释我真的很感激
  • 顺便说一下,库zxing解码二进制位图而不是位图
  • Zxing android 库使用位图,您使用的是 Java SE 包。 github.com/zxing/zxing
  • 我对我的问题的回答可以参考这里(stackoverflow.com/questions/48199282/…)。我无法回答我的问题,我不知道为什么
猜你喜欢
  • 2018-09-07
  • 2015-04-14
  • 2018-09-06
  • 1970-01-01
  • 1970-01-01
  • 2019-06-15
  • 2019-03-29
  • 2016-09-17
  • 1970-01-01
相关资源
最近更新 更多