Commit 2db2470e by fengshuonan

删除二维码生成

parent 2831ef16
/*
* Copyright 2012 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.stylefeng.guns.core.qr;
import java.awt.image.BufferedImage;
/**
* Encapsulates custom configuration used in methods of {@link MatrixToImageWriter}.
*/
public final class MatrixToImageConfig {
public static final int BLACK = 0xFF000000;
public static final int WHITE = 0xFFFFFFFF;
private final int onColor;
private final int offColor;
/**
* Creates a default config with on color {@link #BLACK} and off color {@link #WHITE}, generating normal
* black-on-white barcodes.
*/
public MatrixToImageConfig() {
this(BLACK, WHITE);
}
/**
* @param onColor pixel on color, specified as an ARGB value as an int
* @param offColor pixel off color, specified as an ARGB value as an int
*/
public MatrixToImageConfig(int onColor, int offColor) {
this.onColor = onColor;
this.offColor = offColor;
}
public int getPixelOnColor() {
return onColor;
}
public int getPixelOffColor() {
return offColor;
}
int getBufferedImageColorModel() {
// Use faster BINARY if colors match default
return onColor == BLACK && offColor == WHITE ? BufferedImage.TYPE_BYTE_BINARY : BufferedImage.TYPE_INT_RGB;
}
}
\ No newline at end of file
/*
* Copyright 2009 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.stylefeng.guns.core.qr;
import com.google.zxing.common.BitMatrix;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Path;
/**
* Writes a {@link BitMatrix} to {@link BufferedImage},
* file or stream. Provided here instead of core since it depends on
* Java SE libraries.
*
* @author Sean Owen
*/
public final class MatrixToImageWriter {
private static final MatrixToImageConfig DEFAULT_CONFIG = new MatrixToImageConfig();
private MatrixToImageWriter() {}
/**
* Renders a {@link BitMatrix} as an image, where "false" bits are rendered
* as white, and "true" bits are rendered as black.
*/
public static BufferedImage toBufferedImage(BitMatrix matrix) {
return toBufferedImage(matrix, DEFAULT_CONFIG);
}
/**
* As {@link #toBufferedImage(BitMatrix)}, but allows customization of the output.
*/
public static BufferedImage toBufferedImage(BitMatrix matrix, MatrixToImageConfig config) {
int width = matrix.getWidth();
int height = matrix.getHeight();
BufferedImage image = new BufferedImage(width, height, config.getBufferedImageColorModel());
int onColor = config.getPixelOnColor();
int offColor = config.getPixelOffColor();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, matrix.get(x, y) ? onColor : offColor);
}
}
return image;
}
/**
* @deprecated use {@link #writeToPath(BitMatrix, String, Path)}
*/
@Deprecated
public static void writeToFile(BitMatrix matrix, String format, File file) throws IOException {
writeToPath(matrix, format, file.toPath());
}
/**
* Writes a {@link BitMatrix} to a file.
*
* @see #toBufferedImage(BitMatrix)
*/
public static void writeToPath(BitMatrix matrix, String format, Path file) throws IOException {
writeToPath(matrix, format, file, DEFAULT_CONFIG);
}
/**
* @deprecated use {@link #writeToPath(BitMatrix, String, Path, MatrixToImageConfig)}
*/
@Deprecated
public static void writeToFile(BitMatrix matrix, String format, File file, MatrixToImageConfig config)
throws IOException {
writeToPath(matrix, format, file.toPath(), config);
}
/**
* As {@link #writeToFile(BitMatrix, String, File)}, but allows customization of the output.
*/
public static void writeToPath(BitMatrix matrix, String format, Path file, MatrixToImageConfig config)
throws IOException {
BufferedImage image = toBufferedImage(matrix, config);
if (!ImageIO.write(image, format, file.toFile())) {
throw new IOException("Could not write an image of format " + format + " to " + file);
}
}
/**
* Writes a {@link BitMatrix} to a stream.
*
* @see #toBufferedImage(BitMatrix)
*/
public static void writeToStream(BitMatrix matrix, String format, OutputStream stream) throws IOException {
writeToStream(matrix, format, stream, DEFAULT_CONFIG);
}
/**
* As {@link #writeToStream(BitMatrix, String, OutputStream)}, but allows customization of the output.
*/
public static void writeToStream(BitMatrix matrix, String format, OutputStream stream, MatrixToImageConfig config)
throws IOException {
BufferedImage image = toBufferedImage(matrix, config);
if (!ImageIO.write(image, format, stream)) {
throw new IOException("Could not write an image of format " + format);
}
}
}
\ No newline at end of file
package com.stylefeng.guns.core.qr;
/**
* 二维码图片对象
*
* @author fengshuonan
* @date 2016年12月8日 上午11:37:09
*/
public class QrImage {
/**
* 二维码的内容
*/
private String qrContent;
/**
* 二维码的宽度
*/
private int qrWidth;
/**
* 二维码的高度
*/
private int qrHeight;
/**
* 二维码中间图标的文件路径
*/
private String qrIconFilePath;
/**
* 二维码中间小图标的边长
*/
private int qrIconWidth;
/**
* 顶部文字的高度
*/
private int topWrodHeight;
/**
* 文字的大小
*/
private int wordSize;
/**
* 文字的内容
*/
private String wordContent;
/**
* 文件的输出路径
*/
private String fileOutputPath;
public static class Builder {
private String qrContent;
private int qrWidth;
private int qrHeight;
private String qrIconFilePath;
private int topWrodHeight;
private int wordSize;
private String wordContent;
private String fileOutputPath;
private int qrIconWidth;
public Builder() {
}
public Builder setQrContent(String qrContent) {
this.qrContent = qrContent;
return this;
}
public Builder setQrWidth(int qrWidth) {
this.qrWidth = qrWidth;
return this;
}
public Builder setQrHeight(int qrHeight) {
this.qrHeight = qrHeight;
return this;
}
public Builder setQrIconFilePath(String qrIconFilePath) {
this.qrIconFilePath = qrIconFilePath;
return this;
}
public Builder setTopWrodHeight(int topWrodHeight) {
this.topWrodHeight = topWrodHeight;
return this;
}
public Builder setWordSize(int wordSize) {
this.wordSize = wordSize;
return this;
}
public Builder setWordContent(String wordContent) {
this.wordContent = wordContent;
return this;
}
public Builder setFileOutputPath(String fileOutputPath) {
this.fileOutputPath = fileOutputPath;
return this;
}
public Builder setQrIconWidth(int qrIconWidth) {
this.qrIconWidth = qrIconWidth;
return this;
}
public QrImage build() {
return new QrImage(this.qrContent, this.qrWidth, this.qrHeight, this.qrIconFilePath, this.qrIconWidth,
this.topWrodHeight, this.wordSize, this.wordContent, this.fileOutputPath);
}
}
public QrImage(String qrContent, int qrWidth, int qrHeight, String qrIconFilePath, int qrIconWidth,
int topWrodHeight, int wordSize, String wordContent, String fileOutputPath) {
super();
this.qrContent = qrContent;
this.qrWidth = qrWidth;
this.qrHeight = qrHeight;
this.qrIconFilePath = qrIconFilePath;
this.qrIconWidth = qrIconWidth;
this.topWrodHeight = topWrodHeight;
this.wordSize = wordSize;
this.wordContent = wordContent;
this.fileOutputPath = fileOutputPath;
}
public String getQrContent() {
return qrContent;
}
public int getQrWidth() {
return qrWidth;
}
public int getQrHeight() {
return qrHeight;
}
public String getQrIconFilePath() {
return qrIconFilePath;
}
public int getTopWrodHeight() {
return topWrodHeight;
}
public int getWordSize() {
return wordSize;
}
public String getWordContent() {
return wordContent;
}
public String getFileOutputPath() {
return fileOutputPath;
}
public int getQrIconWidth() {
return qrIconWidth;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment