java中的二维码图像生成器(开源但没有GPL)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1137415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 00:09:41  来源:igfitidea点击:

QR codes image generator in java (open source but no GPL)

javaencodeqr-code

提问by oneeyeHyman

I'm seeking an open source QR codes image generator component in java (J2SE), but the open source licence mustn't be a GPL licence (needs to be included in a close source project).

我正在寻找 Java (J2SE) 中的开源 QR 码图像生成器组件,但开源许可证不能是 GPL 许可证(需要包含在闭源项目中)。

BTW, i can't access the web from the project so no Google API.

顺便说一句,我无法从该项目访问网络,因此没有 Google API。

采纳答案by Sean Owen

Mercer - no, there is an encoder in the library too. com.google.zxing.qrcode.encoder. We provide that in addition to an example web app using Google Chart APIs

Mercer - 不,图书馆里也有一个编码器。com.google.zxing.qrcode.encoder。除了使用 Google Chart API 的示例 Web 应用程序之外,我们还提供

回答by Paolo Moretti

ZXingis is an open-source, multi-format 1D/2D barcode image processing library implemented in Java. It is released under the The Apache License, so it allows use of the source code for the development of proprietary software as well as free and open source software.

ZXing是一个用 Java 实现的开源、多格式一维/二维条码图像处理库。它是在The Apache License发布的,因此它允许使用源代码来开发专有软件以及免费和开源软件。

回答by user517708

MatrixToImageWriter uses BitMatrix, not ByteMatrix as returned by QRCode.getMatrix. by looking at android sourcecode, I found the following proof of concept solution:

MatrixToImageWriter 使用 BitMatrix,而不是 QRCode.getMatrix 返回的 ByteMatrix。通过查看android源代码,我发现了以下概念证明解决方案:

    try {
        MultiFormatWriter writer = new MultiFormatWriter();    
        Hashtable hints = new Hashtable();
        hints.put( EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.Q );            
        MatrixToImageWriter.writeToFile( writer.encode( "hello world", BarcodeFormat.QR_CODE, 800, 800, hints ),
                                         "png", new File( "/tmp/qrcode.png" ) );
    } catch ( Exception e ) {
        System.out.println( "failure: " + e );
    }

btw imposing Hashtable in API is not clean. please use Map. not many people still use Hashtable anyway, you should almost always use HashMap instead (except a few use cases).

顺便说一句,在 API 中强加 Hashtable 并不干净。请使用地图。无论如何,仍然没有多少人使用 Hashtable,您应该几乎总是使用 HashMap 代替(除了少数用例)。