本文整理匯總了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);
}