Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Java generate two-dimensional code by Zxing     - How to understand Python yield keyword (Programming)

- MySQL optimization tabs (Database)

- Debian Stable (Jessie 8.1) of normal.mod not found (Linux)

- Httpclient4.4 of principle (Http execution context) (Programming)

- Linux use iptables ban Ping (Linux)

- APF firewall installation and configuration under Linux (Linux)

- innodb storage engine backup tool --Xtrabackup (Database)

- Let 32 Linux / CentOS system to support more than 4G memory (Linux)

- Linux reserves the rest of the file to delete several (Linux)

- SUSE Linux firewall configuration notes (Linux)

- Brief Linux commands (Linux)

- Process safety monitoring and protection under the Linux operating system (Linux)

- How to cool down your Ubuntu system (Linux)

- Linux beginners should know 12 commands (Linux)

- Compare Swift achieve rapid sorting and sorted Methods (Programming)

- Examples of Exploration Class File (Programming)

- How to make Linux a non-root user uses less than 1024 ports (Linux)

- How do I switch from NetworkManager to systemd-network on Linux (Linux)

- pkg-config to use (Linux)

- The development environment to build Nodejs under Ubuntu 14.04 (Linux)

  Java generate two-dimensional code by Zxing
  Add Date : 2018-11-21      
  Java generate two-dimensional code by Zxing

1. Basic class provides two-dimensional code generation tools

package com.green.util;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import javax.imageio.ImageIO;
import com.google.zxing.common.BitMatrix;
public final class MatrixToImageWriter {

    private static final int BLACK = 0xFF000000;

    private static final int WHITE = 0xFFFFFFFF;

    private MatrixToImageWriter () {


    public static BufferedImage toBufferedImage (BitMatrix matrix) {

        int width = matrix.getWidth ();

        int height = matrix.getHeight ();

        BufferedImage image = new BufferedImage (width, height, BufferedImage.TYPE_INT_RGB);

        for (int x = 0; x
            for (int y = 0; y
                image.setRGB (? x, y, matrix.get (x, y) BLACK: WHITE);



        return image;


    public static void writeToFile (BitMatrix matrix, String format, File file) throws IOException {

        BufferedImage image = toBufferedImage (matrix);

        if (! ImageIO.write (image, format, file)) {

            throw new IOException ( "Could not write an image of format" + format + "to" + file);




    public static byte [] writeToStream (BitMatrix matrix, String format) throws IOException {

        ByteArrayOutputStream stream = new ByteArrayOutputStream ();

        BufferedImage image = toBufferedImage (matrix);


        if (! ImageIO.write (image, format, stream)) {

            throw new IOException ( "Could not write an image of format" + format);


        return stream.toByteArray ();



2. Call the utility method to obtain a binary image

package com.green.util;


import java.io.File;

import java.io.IOException;

import java.util.Hashtable;


import com.google.zxing.BarcodeFormat;

import com.google.zxing.EncodeHintType;

import com.google.zxing.MultiFormatWriter;

import com.google.zxing.WriterException;

import com.google.zxing.common.BitMatrix;


/ **


 * /

public class QrCodeGenerator {

    public static byte [] build (String content) throws IOException, WriterException {

            int width = 300;

            int height = 300;

            String format = "gif";

            Hashtable hints = new Hashtable ();

            hints.put (EncodeHintType.CHARACTER_SET, "utf-8");

            BitMatrix bitMatrix = new MultiFormatWriter (). Encode (content,

                    BarcodeFormat.QR_CODE, width, height, hints);

          return MatrixToImageWriter.writeToStream (bitMatrix, format);


- Linux boot process (Linux)
- Use LVM partition on Ubuntu and easily adjust the snapshot (Linux)
- Ubuntu 14.04 How to set up an SSH without password (Linux)
- How to Use Nmap security scanner tool on Linux (Linux)
- How to view the Linux program or process used in the library (Linux)
- Android Unzip the ZIP / GZIP data (based on the InflaterInputStream implementation) (Programming)
- Local port forwarding using iptables under linux (Server)
- How to manage and use Logical Volume Management LVM in Ubuntu (Linux)
- To setup Cocos2dx project under Ubuntu (Linux)
- Mongo-connector integrated MongoD to achieve incremental Solr index (Server)
- After installing minimize RHEL / CentOS 7 need to do some things (Linux)
- Ubuntu 14.04 next upgrade to GNOME 3.12 (Linux)
- How to install Eclipse Luna IDE on CentOS 7 / RHEL 7 (Linux)
- How to use the Linux command compress JPEG images (Linux)
- Three strategies to teach you to release the device memory (Linux)
- To repair Shell script by default open in Ubuntu (Linux)
- Zabbix monitoring disk IO status (Server)
- The new features of MySQL 5.7 Generated Column (index function) (Database)
- Spring + Log4j + ActiveMQ remote logging - Analysis of combat (Server)
- Linux use glibc2 library and crypt () function to generate the user password (Programming)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.