本文整理汇总了Java中com.google.zxing.client.j2se.MatrixToImageWriter.writeToFile方法的典型用法代码示例。如果您正苦于以下问题:Java MatrixToImageWriter.writeToFile方法的具体用法?Java MatrixToImageWriter.writeToFile怎么用?Java MatrixToImageWriter.writeToFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.zxing.client.j2se.MatrixToImageWriter
的用法示例。
在下文中一共展示了MatrixToImageWriter.writeToFile方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encode2
import com.google.zxing.client.j2se.MatrixToImageWriter; //导入方法依赖的package包/类
/**
* 二维码编码
*
* @param contents
* @param width
* @param height
* @param imgPath
*/
public static void encode2(String contents, int width, int height, String imgPath) {
Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
// 指定纠错等级
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
// 指定编码格式
hints.put(EncodeHintType.CHARACTER_SET, "GBK");
try {
BitMatrix bitMatrix = new MultiFormatWriter().encode(contents,
BarcodeFormat.QR_CODE, width, height, hints);
MatrixToImageWriter
.writeToFile(bitMatrix, "png", new File(imgPath));
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: barCode
import com.google.zxing.client.j2se.MatrixToImageWriter; //导入方法依赖的package包/类
public static void barCode(String contents,String imgPath,int width, int height) {
int codeWidth = 3 + // start guard
(7 * 6) + // left bars
5 + // middle guard
(7 * 6) + // right bars
3; // end guard
codeWidth = Math.max(codeWidth, width);
try {
BitMatrix bitMatrix = new MultiFormatWriter().encode(contents,BarcodeFormat.CODE_128, codeWidth, height, null);
bitMatrix = deleteWhite(bitMatrix);
MatrixToImageWriter.writeToFile(bitMatrix, "png", new File(imgPath));
}catch (Exception e) {
log.error(e.getMessage());
e.printStackTrace();
}
}
示例3: encode
import com.google.zxing.client.j2se.MatrixToImageWriter; //导入方法依赖的package包/类
/**
* 条形码编码
*
* @param contents
* @param width
* @param height
* @param imgPath
*/
public static void encode(String contents, int width, int height, String imgPath) {
int codeWidth = 3 + // start guard
(7 * 6) + // left bars
5 + // middle guard
(7 * 6) + // right bars
3; // end guard
codeWidth = Math.max(codeWidth, width);
try {
BitMatrix bitMatrix = new MultiFormatWriter().encode(contents,
BarcodeFormat.EAN_13, codeWidth, height, null);
MatrixToImageWriter
.writeToFile(bitMatrix, "png", new File(imgPath));
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: genQrCodeToFile
import com.google.zxing.client.j2se.MatrixToImageWriter; //导入方法依赖的package包/类
/**
*生成二维码图片并保存为文件
* @param content 文本内容
* @param output 目标文件
* @param format 图片格式
* @param width 宽
* @param height 高
* @throws WriterException
* @throws IOException
*/
public static void genQrCodeToFile(String content, File output, String format, Integer width,
Integer height) throws WriterException, IOException {
if (width == null) {
width = QrCodeUtil.width; // 图像宽度
}
if (height == null) {
height = QrCodeUtil.height; // 图像高度
}
if (format == null) {
format = QrCodeUtil.format; //文件格式
}
Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
BitMatrix bitMatrix =
new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints); // 生成矩阵
MatrixToImageWriter.writeToFile(bitMatrix, format, output);
}
示例5: qrCode
import com.google.zxing.client.j2se.MatrixToImageWriter; //导入方法依赖的package包/类
public static void qrCode(int width,int height,String content,String suffix,String imgPath){
Hashtable<EncodeHintType, String> hints= new Hashtable<EncodeHintType, String>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
BitMatrix bitMatrix;
try {
bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height,hints);
bitMatrix = deleteWhite(bitMatrix);
File outputFile = new File(imgPath);
MatrixToImageWriter.writeToFile(bitMatrix, suffix, outputFile);
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: createQRCode
import com.google.zxing.client.j2se.MatrixToImageWriter; //导入方法依赖的package包/类
public static void createQRCode(String qrCodeData, String filePath,
String charset, Map hintMap, int qrCodeheight, int qrCodewidth)
throws WriterException, IOException {
BitMatrix matrix = new MultiFormatWriter().encode(
new String(qrCodeData.getBytes(charset), charset),
BarcodeFormat.QR_CODE, qrCodewidth, qrCodeheight, hintMap);
Object object = new Object();
MatrixToImageWriter.writeToFile(matrix, filePath.substring(filePath
.lastIndexOf('.') + 1), new File(filePath));
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-2-spraguesanborn,代码行数:15,代码来源:QRCodeMaker.java
示例7: createQrCode
import com.google.zxing.client.j2se.MatrixToImageWriter; //导入方法依赖的package包/类
/**
* 生成二维码
* @param content
* @param storePath
* @return
*/
@SuppressWarnings("deprecation")
public String createQrCode(String content, String storePath){
String savePath = null;
try {
File tmpFile = File.createTempFile("tmp_", ".png");
QRCodeWriter writer = new QRCodeWriter();
BitMatrix matrix = writer.encode(content, BarcodeFormat.QR_CODE, 200, 200);
MatrixToImageWriter.writeToFile(matrix, "png", tmpFile);
savePath = fileUtils.uploadFromLocal(tmpFile, storePath);
} catch (IOException | WriterException e) {
Exceptions.printException(e);
}
return savePath;
}
示例8: benchmark
import com.google.zxing.client.j2se.MatrixToImageWriter; //导入方法依赖的package包/类
@Test
void benchmark() throws WriterException, IOException
{
QRCodeWriter qrCodeWriter=new QRCodeWriter();
String url="https://isqrl.allogy.com/scan/8b775f16d8fc58dc8fe38c87f66e55d973e23407/A3k2TjrkimptR.png";
BarcodeFormat barcodeFormat=BarcodeFormat.QR_CODE;
int width =150;
int height=150;
BitMatrix bitMatrix = qrCodeWriter.encode(url, barcodeFormat, width, height);
//MatrixToImageWriter.writeToStream(bitMatrix, "PNG", outputStream);
MatrixToImageWriter.writeToFile(bitMatrix, "PNG", new File("/tmp/qr.png"));
}
示例9: generate
import com.google.zxing.client.j2se.MatrixToImageWriter; //导入方法依赖的package包/类
/**
* Generate QRCode.
*
* @param file
* file
* @throws Exception
*/
public void generate(final File file) throws Exception {
BitMatrix bitMatrix = createBitMatrix();
MatrixToImageWriter.writeToFile(bitMatrix, imageFormat, file);
}