JAVA 压缩图片-解析一维码二维码

来源:互联网 发布:淘宝店铺上新提醒设置 编辑:程序博客网 时间:2024/05/16 12:29

首先使用这个类来压缩图片:

相关包下载

CompressPicDemo

CompressPicDemo mypic = new CompressPicDemo(); //创建压缩图对象//compressPic(大图片路径,生成小图片路径,大图片文件名,生成小图片文名,生成小图片宽度,生成小图片高度,是否等比缩放(默认为true))mypic.compressPic("c:\\原图片路径", "c:\\输出图片路径", "原图片.后缀", "输出图.后缀", 600, 600, true);

然后使用ZXING来解码

用到的包 core-2.0.jar javase-1.7.jar

//解码BufferedImage image = null;  Result result = null;  //com.google.zxing.Resultimage = ImageIO.read(new File(imgPath));if (image == null) {System.out.println("the decode image may be not exit."); }LuminanceSource source = new BufferedImageLuminanceSource(image);BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); result = new MultiFormatReader().decode(bitmap, null);String decodeContent = result.getText();System.out.println("解码内容如下:" + decodeContent);



0 0