栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java学习笔记:检测一堆图片文件中是否有包含二维码的

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java学习笔记:检测一堆图片文件中是否有包含二维码的

案例一

package part2;

import com.google.zxing.Result;
import com.yzk18.commons.IOHelpers;
import com.yzk18.commons.QRCodeHelpers;

import java.util.Arrays;

public class 检测二维码 {
    public static void main(String[] args) {
        String[] files=IOHelpers.getFilesRecursively("D:\temp\img","png","jpg","gif");//将文件夹下的"png","jpg","gif"文件找到
        System.out.println(Arrays.toString(files));
        Boolean qrcodeFound=false;
        for (String file:files)
        {
            //经过试验发现,如果图片没有二维码返回值为null
            Result result=QRCodeHelpers.parseImage(file);//尝试从file这个文件中解析出来条形码。
            //System.out.println(result);
            if (result!=null)//只要找到一个二维码就退出,结果为true
            {
                //System.out.println("有二维码");
                qrcodeFound=true;
                break;
            }
            if (qrcodeFound)
            {
                System.out.println("有二维码");
            }
            else
            {
                System.out.println("没有二维码");
            }
        }
    }
}

 案例二:

package part2;

import com.google.zxing.Result;
import com.yzk18.commons.IOHelpers;
import com.yzk18.commons.QRCodeHelpers;

import javax.naming.spi.DirStateFactory;
import java.util.Arrays;

public class 检测二维码2 {
    public static void main(String[] args) {
        String files[] = IOHelpers.getFilesRecursively("d:/temp", "jpg", "png");
        System.out.println(Arrays.toString(files));
        Boolean yici=false;
        for (String file : files) {
            Result qrcode = QRCodeHelpers.parseImage(file);
            //System.out.println(qrcode);
            if (qrcode == null)
            {
                System.out.println("检测通过");
            }
            else
            {
                if (qrcode.getText().contains("http")||qrcode.getText().contains("https"))
                {
                    System.out.println("有宣传性二维码图片");
                }
                else
                {
                    System.out.println("检测通过");
                }
            }
        }

    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/713327.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号