+
 新版

想做一个网站根据提交图片识别解析二维码,想从内存流中读取图片信息,求zxing内存流接口~~~~~

斯乌和凹 发布于 2016/08/22 12:52
阅读 1K+
收藏 1
因为这个接口是文件路径,但是做网站不能这样读取,想直接从内存流中读取,求教大神应该这么做?~~~


public void testDecode()


{  
        String filePath = "k://zxing.png";  
        BufferedImage image;  
        try {  
            image = ImageIO.read(new File(filePath));  
            LuminanceSource source = new BufferedImageLuminanceSource(image);  
            Binarizer binarizer = new HybridBinarizer(source);  
            BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer);  
            Map<DecodeHintType, Object> hints = new HashMap<DecodeHintType, Object>();  
            hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");  
            Result result = new MultiFormatReader().decode(binaryBitmap, hints);// 对图像进行解码 
            JSONObject content = JSONObject.fromObject(result.getText()); 
            System.out.println("图片中内容:  ");  
            System.out.println("author: " + content.getString("author"));  
            System.out.println("zxing:  " + content.getString("zxing"));  
            System.out.println("图片中格式:  ");  
            System.out.println("encode: " + result.getBarcodeFormat());  
            
            
            
            
            
        }
        catch (IOException e) 
        {  
            e.printStackTrace();  
        } 
        catch (NotFoundException e)
        {  
            e.printStackTrace();  
        }  





    }  

加载中
0
szwx855
szwx855
可以使用apache中的FileUtils.copy方法。来完成流copy,生成一个文件,然后你读取这个文件生成二维码。生成完毕后,删除刚才生成的这个文件即可。
斯
斯乌和凹
谢谢您的回答,我试试~
0
b
beastxiao
我以前也打算做个,发现开源中国有这工具,就没做了
斯
斯乌和凹
谢谢你~求连接或者项目名称啊,不好意思没找到~
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部