Use ImageIO to read network pictures (QR code) or local pictures

From the network

Use ImageIO to read network pictures (QR code) or local pictures

One read network picture

    public static String analysisReadQRCode(String path){
        MultiFormatReader multiFormatReader=new MultiFormatReader();
        HashMap hints=new HashMap();
        hints.put(EncodeHintType.CHARACTER_SET,"GBK");
        try{
            URL url = new URL(path);
            BufferedImage source= ImageIO.read(url);
            BinaryBitmap binaryImg=new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(source)));
            Result result=multiFormatReader.decode(binaryImg,hints);
            return result.getText();
        }catch (Exception e){
            e.printStackTrace();
        }
        return "";
    }

 

Two read network pictures

public static String analysisReadQRCode(String path){
        MultiFormatReader multiFormatReader=new MultiFormatReader();
        HashMap hints=new HashMap();
        hints.put(EncodeHintType.CHARACTER_SET,"GBK");
        try{
            BufferedImage source= ImageIO.read(new File(path));
            BinaryBitmap binaryImg=new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(source)));
            Result result=multiFormatReader.decode(binaryImg,hints);
            return result.getText();
        }catch (Exception e){
            e.printStackTrace();
        }
        return "";
    }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/huanglianggu/article/details/113631335