導航:首頁 > 編程語言 > javazxing文字

javazxing文字

發布時間:2023-11-25 18:59:32

『壹』 java 如何向ZeBra列印機發送字元串

可以參考下.自己寫的一個例子

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.util.Queue;

import com.google.zxing.WriterException;
public class QrPrint implements Printable {
public void print() throws PrinterException {
PrinterJob pj = PrinterJob.getPrinterJob();
PageFormat pf = pj.defaultPage();
Paper paper = new Paper();
double margin = 0.1; // half inch
paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2,paper.getHeight() - margin * 2);
pf.setPaper(paper);
pj.setPrintable(this, pf);
pj.print();
}
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
if ("判斷如果列印完了就退出") {
return Printable.NO_SUCH_PAGE;
}
try {
Image eanImage = generateEANBufferedImage(content,120,20);
Graphics2D g2 = (Graphics2D) graphics;
g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); //設置可成像的和Y軸的距離
g2.drawImage(eanImage, 0, 80, null); //設置列印的邊距
g2.drawString("字元串:",130,20);
} catch (WriterException e) {
e.printStackTrace();
return Printable.NO_SUCH_PAGE;
}
return Printable.PAGE_EXISTS;
}
private BufferedImage generateBufferedImage(String content,int width,int height) throws WriterException {
Hashtable<EncodeHintType,String> hints = new Hashtable<EncodeHintType,String>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.EAN_13, width, height, hints);
return MatrixToImageWriter.toBufferedImage(bitMatrix);
}

}

『貳』 java中zxing二維碼怎麼在掃描的時候跳轉到指定頁面

有沒有沒解決的?找到方法了,

@SuppressWarnings({"rawtypes","unchecked"})
privatestaticvoidcreateZxing()throwsWriterException,IOException{

intwidth=300;
inthight=300;
Stringformat="png";
Stringcontent="https://www..com";//這里要注意!!!!!!!
HashMaphints=newHashMap();
hints.put(EncodeHintType.CHARACTER_SET,"utf-8");
hints.put(EncodeHintType.ERROR_CORRECTION,
+ErrorCorrectionLevel.M);//糾錯等級L,M,Q,H
hints.put(EncodeHintType.MARGIN,2);//邊距
BitMatrixbitMatrix=newMultiFormatWriter().encode(content,
+BarcodeFormat.QR_CODE,width,hight,hints);
Filefile=newFile("D:/imag.png");
MatrixToImageWriter.writeToFile(bitMatrix,format,file);
}
/*你需要跳轉的頁面前面加上http協議,掃描的軟體比方說:微信,它會直接識別http
協議*/

『叄』 java 生成二維碼後如何給該二維碼添加信息

java可使用zxing生成二維碼並為其添加信息。
以下是詳細步驟:
1、創建MatrixToImageWriter類

importcom.google.zxing.common.BitMatrix;
importjavax.imageio.ImageIO;
importjava.io.File;
importjava.io.OutputStream;
importjava.io.IOException;
importjava.awt.image.BufferedImage;


{

privatestaticfinalintBLACK=0xFF000000;
privatestaticfinalintWHITE=0xFFFFFFFF;

privateMatrixToImageWriter(){}


(BitMatrixmatrix){
intwidth=matrix.getWidth();
intheight=matrix.getHeight();
BufferedImageimage=newBufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
for(intx=0;x<width;x++){
for(inty=0;y<height;y++){
image.setRGB(x,y,matrix.get(x,y)?BLACK:WHITE);
}
}
returnimage;
}


publicstaticvoidwriteToFile(BitMatrixmatrix,Stringformat,Filefile)
throwsIOException{
BufferedImageimage=toBufferedImage(matrix);
if(!ImageIO.write(image,format,file)){
thrownewIOException("Couldnotwriteanimageofformat"+format+"to"+file);
}
}


publicstaticvoidwriteToStream(BitMatrixmatrix,Stringformat,OutputStreamstream)
throwsIOException{
BufferedImageimage=toBufferedImage(matrix);
if(!ImageIO.write(image,format,stream)){
thrownewIOException("Couldnotwriteanimageofformat"+format);
}
}

}


2、生成二維碼並添加信息

importjava.io.File;
importjava.util.Hashtable;

importcom.google.zxing.BarcodeFormat;
importcom.google.zxing.EncodeHintType;
importcom.google.zxing.MultiFormatWriter;
importcom.google.zxing.WriterException;
importcom.google.zxing.common.BitMatrix;

publicclassTest{

/**
*@paramargs
*@throwsException
*/
publicstaticvoidmain(String[]args)throwsException{
Stringtext="http://www..com";
intwidth=300;
intheight=300;
//二維碼的圖片格式
Stringformat="gif";
Hashtablehints=newHashtable();
//內容所使用編碼
hints.put(EncodeHintType.CHARACTER_SET,"utf-8");
BitMatrixbitMatrix=newMultiFormatWriter().encode(text,
BarcodeFormat.QR_CODE,width,height,hints);
//生成二維碼
FileoutputFile=newFile("d:"+File.separator+"new.gif");
MatrixToImageWriter.writeToFile(bitMatrix,format,outputFile);

}

}

『肆』 如何使攝像頭掃描二維碼,然後解析二維碼 java源碼 zxing

import com.google.zxing.common.BitMatrix;

import javax.imageio.ImageIO;
import java.io.File;
import java.io.OutputStream;
import java.io.IOException;
import java.awt.image.BufferedImage;

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 < width; x++) {
for (int y = 0; y < height; 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 (!.write(image, format, file)) {
throw new IOException("Could not write an image of format " + format + " to " + file);
}
}

public static void writeToStream(BitMatrix matrix, String format, OutputStream stream)
throws IOException {
BufferedImage image = toBufferedImage(matrix);
if (!ImageIO.write(image, format, stream)) {
throw new IOException("Could not write an image of format " + format);
}
}

}

閱讀全文

與javazxing文字相關的資料

熱點內容
中間夾菜單裡面不能顯示壓縮文件 瀏覽:952
如何指導小學生參加編程比賽 瀏覽:275
物業的招標文件有哪些 瀏覽:452
保存游戲文件名非法或只讀 瀏覽:258
js怎麼做圖片時鍾 瀏覽:451
華為應用裡面有了app說明什麼 瀏覽:801
資料庫中xy是什麼意思 瀏覽:893
u盤打不開提示找不到應用程序 瀏覽:609
網站功能介紹怎麼寫 瀏覽:954
word在試圖打開文件時錯誤 瀏覽:108
主板無vga插槽怎麼連接編程器 瀏覽:521
錄視頻文件在哪裡刪除 瀏覽:881
word2013如何插入文件 瀏覽:233
proe教程百度網盤 瀏覽:197
如何控制遠程linux伺服器 瀏覽:740
it教學app有哪些 瀏覽:34
怎麼在ps摳的圖變成矢量文件 瀏覽:405
口袋妖怪銀魂安卓v11 瀏覽:1
網站上芒果tv的賬號都是什麼 瀏覽:104
帶公式的表格如何刷新數據 瀏覽:81

友情鏈接