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

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

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("检测通过");
                }
            }
        }

    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5709977.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存