本文整理汇总了Java中com.google.zxing.client.j2se.MatrixToImageConfig类的典型用法代码示例。如果您正苦于以下问题:Java MatrixToImageConfig类的具体用法?Java MatrixToImageConfig怎么用?Java MatrixToImageConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MatrixToImageConfig类属于com.google.zxing.client.j2se包,在下文中一共展示了MatrixToImageConfig类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encode
import com.google.zxing.client.j2se.MatrixToImageConfig; //导入依赖的package包/类
/**
* Zxing图形码生成工具
*
* @param contents
* 内容
* @param barcodeFormat
* BarcodeFormat对象
* @param format
* 图片格式,可选[png,jpg,bmp]
* @param width
* 宽
* @param height
* 高
* @param margin
* 边框间距px
* @param saveImgFilePath
* 存储图片的完整位置,包含文件名
* @return {boolean}
*/
public static boolean encode(String contents, BarcodeFormat barcodeFormat, Integer margin,
ErrorCorrectionLevel errorLevel, String format, int width, int height, String saveImgFilePath) {
Boolean bool = false;
BufferedImage bufImg;
Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
// 指定纠错等级
hints.put(EncodeHintType.ERROR_CORRECTION, errorLevel);
hints.put(EncodeHintType.MARGIN, margin);
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
try {
// contents = new String(contents.getBytes("UTF-8"), "ISO-8859-1");
BitMatrix bitMatrix = new MultiFormatWriter().encode(contents, barcodeFormat, width, height, hints);
MatrixToImageConfig config = new MatrixToImageConfig(0xFF000001, 0xFFFFFFFF);
bufImg = MatrixToImageWriter.toBufferedImage(bitMatrix, config);
bool = writeToFile(bufImg, format, saveImgFilePath);
} catch (Exception e) {
e.printStackTrace();
}
return bool;
}
示例2: encode
import com.google.zxing.client.j2se.MatrixToImageConfig; //导入依赖的package包/类
/**
* Zxing图形码生成工具
*
* @param contents 内容
* @param barcodeFormat BarcodeFormat对象
* @param format 图片格式,可选[png,jpg,bmp]
* @param width 宽
* @param height 高
* @param margin 边框间距px
* @param saveImgFilePath 存储图片的完整位置,包含文件名
* @return
*/
public Boolean encode(String contents, BarcodeFormat barcodeFormat, Integer margin, ErrorCorrectionLevel errorLevel, String format, int width, int height, String saveImgFilePath) {
Boolean bool;
BufferedImage bufImg;
Map<EncodeHintType, Object> hints = new HashMap<>();
// 指定纠错等级
hints.put(EncodeHintType.ERROR_CORRECTION, errorLevel);
hints.put(EncodeHintType.MARGIN, margin);
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
try {
// contents = new String(contents.getBytes("UTF-8"), "ISO-8859-1");
BitMatrix bitMatrix = new MultiFormatWriter().encode(contents, barcodeFormat, width, height, hints);
MatrixToImageConfig config = new MatrixToImageConfig(0xFF000001, 0xFFFFFFFF);
bufImg = MatrixToImageWriter.toBufferedImage(bitMatrix, config);
bool = this.writeToFile(bufImg, format, saveImgFilePath);
} catch (Throwable t) {
log.error("encode-ex:{}", t);
throw Throwables.propagate(t);
}
return bool;
}
示例3: toBufferedImage
import com.google.zxing.client.j2se.MatrixToImageConfig; //导入依赖的package包/类
/**
* Testing utility that converts BitmapImage to BufferedImage type.
*/
protected static BufferedImage toBufferedImage(BitmapImage matrix) {
MatrixToImageConfig config = new MatrixToImageConfig();
int width = matrix.getWidth();
int height = matrix.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
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;
}
示例4: writeToStream
import com.google.zxing.client.j2se.MatrixToImageConfig; //导入依赖的package包/类
private void writeToStream(OutputStream stream) throws IOException, WriterException {
MatrixToImageWriter.writeToStream(this.createMatrix(), this.imageType, stream, new MatrixToImageConfig(
this.onColor, this.offColor));
}
示例5: createQRCodeImageFile
import com.google.zxing.client.j2se.MatrixToImageConfig; //导入依赖的package包/类
/**
* 创建 QRCode 图片文件
*
* @param file 图片
* @param imageFormat 图片编码格式
* @param encodeContent QRCode 内容
* @param imageSize 图片大小
* @param foreGroundColor 前景色
* @param backGroundColor 背景色
* @throws WriterException
* @throws IOException
*/
public static void createQRCodeImageFile(Path file, ImageFormat imageFormat, String encodeContent, Dimension imageSize, Color foreGroundColor, Color backGroundColor) throws WriterException, IOException {
Assert.isTrue(FilenameUtils.getExtension(file.toString()).toUpperCase().equals(imageFormat.toString()), "文件扩展名和格式不一致");
QRCodeWriter qrWrite = new QRCodeWriter();
BitMatrix matrix = qrWrite.encode(encodeContent, BarcodeFormat.QR_CODE, imageSize.width, imageSize.height);
MatrixToImageWriter.writeToPath(matrix, imageFormat.toString(), file, new MatrixToImageConfig(foreGroundColor.getRGB(), backGroundColor.getRGB()));
}
示例6: createQRCodeImageStream
import com.google.zxing.client.j2se.MatrixToImageConfig; //导入依赖的package包/类
/**
* 创建 QRCode 图片文件输出流,用于在线生成动态图片
*
* @param stream
* @param imageFormat
* @param encodeContent
* @param imageSize
* @param foreGroundColor
* @param backGroundColor
* @throws WriterException
* @throws IOException
*/
public static void createQRCodeImageStream(OutputStream stream, ImageFormat imageFormat, String encodeContent, Dimension imageSize, Color foreGroundColor, Color backGroundColor) throws WriterException, IOException {
QRCodeWriter qrWrite = new QRCodeWriter();
BitMatrix matrix = qrWrite.encode(encodeContent, BarcodeFormat.QR_CODE, imageSize.width, imageSize.height);
MatrixToImageWriter.writeToStream(matrix, imageFormat.toString(), stream, new MatrixToImageConfig(foreGroundColor.getRGB(), backGroundColor.getRGB()));
}