导航:首页 > 编程语言 > 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文字相关的资料

热点内容
501完美越狱工具 浏览:119
中间夹菜单里面不能显示压缩文件 浏览: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

友情链接