Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java generate two-dimensional code by Zxing     - Detailed iptables (Linux)

- See Shell Script Linux Server network traffic (Server)

- Android project and coding specifications (Programming)

- On event processing browser compatibility notes (Programming)

- Linux, how to filter, split, and merge pcap file (Linux)

- Linux server network penetration testing (Linux)

- Talking about the implementation and the JVM garbage collection mechanism (Programming)

- I use the desktop environment in GNU / Linux combination tool (Linux)

- PHP 7.0 Upgrade Notes (Linux)

- Nginx Module Development - get user ip (Server)

- Different versions of MongoDB achieve master-slave replication (Database)

- Linux Getting Started tutorial: hard disk partition and to deal with traps (Linux)

- Linux compiler of GCC (Linux)

- Oracle 11g RMAN cross-platform transfer table space (Database)

- SA weak password security system of the security risks posed (Linux)

- Ubuntu Apache virtual host configuration (Server)

- JVM garbage collector and memory allocation strategy (Programming)

- Ubuntu 14.04 build Hadoop 2.5.1 standalone and pseudo-distributed environment (32-bit) (Server)

- Linux boot the system does not display a progress bar setting method (Linux)

- 10 Regulation of painless SQL Schema (Database)

 
         
  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);

    }

}
     
         
         
         
  More:      
 
- Oracle Database routine inspection (Database)
- Video editing captions under Linux (Linux)
- Elasticsearch 2.20 Beginners: aggregation (Server)
- CentOS 6 rapid deployment of Java applications (Linux)
- Observation network performance tools for Linux (Linux)
- C ++ Supplements - locates the new expression (Programming)
- To install file manager Nautilus 3.12.2 under ubuntu (Linux)
- CentOS 7 x64 compiler installation Tengine 2.0.3 Comments (Server)
- Realization of Linux operating system illegal IP censorship (Linux)
- Java generate two-dimensional code by Zxing (Programming)
- MySQL Tutorial: Some optimized for I / O memory areas (Database)
- An Analysis of the C Algorithm for Calculating the Number of Days Between Date (Programming)
- CentOS 7.0 Enable iptables firewall (Linux)
- Construction of Android and iOS apps use Jenkins Automation (Programming)
- MySQL + Corosync + Pacemaker + DRBD build highly available MySQL (Server)
- To compile and install MySQL 5.7.7 RC under CentOS 7.1 (Database)
- Android Action Compendium (Programming)
- LVM basic concepts, management (Linux)
- Remove old kernel on Ubuntu (Linux)
- Install Debian Linux with R on the Android system (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.