zoukankan      html  css  js  c++  java
  • QRGen+thumbnailator生成包含logo 参考配置说明

    以下主要是说明下生成的一些细节,减少使用难度

    参考代码

    • pom.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.dalong</groupId>
        <artifactId>imageapp</artifactId>
        <version>1.0-SNAPSHOT</version>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>8</source>
                        <target>8</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        <repositories>
            <repository>
                <id>jitpack.io</id>
                <url>https://jitpack.io</url>
            </repository>
        </repositories>
       <dependencies>
           <dependency>
               <groupId>apache-codec</groupId>
               <artifactId>commons-codec</artifactId>
               <version>1.2</version>
           </dependency>
           <dependency>
               <groupId>com.github.kenglxn.qrgen</groupId>
               <artifactId>javase</artifactId>
               <version>2.6.0</version>
           </dependency>
           <dependency>
               <groupId>net.coobird</groupId>
               <artifactId>thumbnailator</artifactId>
               <version>0.4.8</version>
           </dependency>
       </dependencies>
    </project>
    • 代码
    package com.dalong;
    import net.coobird.thumbnailator.Thumbnails;
    import net.coobird.thumbnailator.geometry.Positions;
    import net.coobird.thumbnailator.resizers.configurations.AlphaInterpolation;
    import net.glxn.qrgen.core.image.ImageType;
    import net.glxn.qrgen.javase.QRCode;
    import org.apache.commons.codec.binary.Base64;
    import javax.imageio.ImageIO;
    import java.io.*;
    public class Application {
            public static void main(String[] args) throws IOException {
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                // 符合黑白模式的,推荐withColor 的第一个参数为0xFF000000,这样保障生成的二维码具有比较高的识别度
                File file =   QRCode.from("https://github.com/rongfengliang").withColor(0xFF000000, 0xf7f7f7).to(ImageType.PNG).withSize(300, 300).file();
               // 基于水印模式进行logo的添加,推荐水印配置alphaInterpolation为AlphaInterpolation.QUALITY
                Thumbnails.of(file)
                    .size(300, 300)
                    .allowOverwrite(true)
                   .keepAspectRatio(true)
                    .alphaInterpolation(AlphaInterpolation.QUALITY)
           .watermark(Positions.CENTER, ImageIO.read(Application.class.getClassLoader().getResourceAsStream("yyy.png")), 1f)
                    .toOutputStream(outputStream);
                byte[] encodedBytes = Base64.encodeBase64(outputStream.toByteArray());
                System.out.println(new String(encodedBytes));
            }
    }

    参考资料

    https://github.com/kenglxn/QRGen
    https://github.com/coobird/thumbnailator

  • 相关阅读:
    CPU、内存、硬盘、指令之间的关系
    hadoop配置
    python logging
    python 多线程一(lock)
    Python+OpenCV图像处理(七)—— 滤波与模糊操作
    Python+OpenCV图像处理(六)—— ROI与泛洪填充
    Python+OpenCV图像处理(五)—— 像素运算
    The MathType Dll cannot be found 问题解决办法
    Python+OpenCV图像处理(四)—— 色彩空间
    Python+OpenCV图像处理(三)—— Numpy数组操作图片
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/13825820.html
Copyright © 2011-2022 走看看