Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Java generate two-dimensional code by Zxing     - To create a secure network firewall with iptables Under Linux (Linux)

- Memcached source installation and configuration under CentOS 6.6 (Server)

- CentOS 6.5 using Virtualenv under development environment to build Python3 (Linux)

- The most common and most effective security settings under linux (Linux)

- Ubuntu 14.04 How to install Cinnamon 2.4.5 (Linux)

- Linux System Getting Started Tutorial: how to find information on Linux-embedded module (Linux)

- Python Django direct implementation of sql statement (Programming)

- Memcached and Redis (Linux)

- MySQL IO SSD attempt at optimization (Database)

- Nginx Keepalived Nginx monitoring scripts (Server)

- Linux operating system log system (Linux)

- The multiplexed signal driving IO (Programming)

- Can not remember how to solve the problem under Ubuntu brightness setting (Linux)

- Linux command ls (Linux)

- Analysis RabbitMQ cluster (Server)

- Linux virtual machine how to access the Internet in a virtual machine when using NAT mode (Linux)

- Ubuntu 15.10 under Python + Apache + CGI fully configured (Server)

- CentOS 7 server environment to quickly build Linux (Server)

- JavaScript Advanced Programming notes event capture and event bubbling (Programming)

- Linux system with a firewall to prevent the DOS attack (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);


- CentOS install expect (Linux)
- Installation and use of Linux Sniffer tool Tcpdump (Linux)
- Spring next ActiveMQ combat (Programming)
- Java Network Programming Internet address lookup (Programming)
- IOwait Linux system monitoring diagnostic tools (Linux)
- Java-based data source database access (Programming)
- CentOS How quickly customize kernel binary RPM package (Linux)
- Shell script on the variables with double quotation marks grep small problem (Programming)
- Oracle inline view updates problems encountered (Database)
- Sort search algorithm Java - application examples with recursive dichotomy (Programming)
- Distributed transaction management Spring declarative transactions (Programming)
- Linux environment SSH login password instead of using the RSA Certificate (Linux)
- jQuery update the content and method of use 3.0 (Programming)
- Ubuntu 12.04 installed OpenCV 2.3.1, binary image (Linux)
- How to use the internal network IP forwarding to connect to the Internet on Linux (Linux)
- Upgrading to MySQL 5.7.9 MySQL 5.6.23 (Database)
- Java Database Programming JDBC configuration (Programming)
- Ubuntu 15.04 installation Powercommands 2.0 (Linux)
- About enhanced Linux / Unix server system security program (Linux)
- How to modify the SQL Server auto-increment value and the corresponding solution (Database)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.