Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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)

Full code below here;

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
318 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...