通过barcode4j生成
@Controller
@RequestMapping("/bar/{code}")
public class BarCodeController {
@RequestMapping(method = RequestMethod.GET)
public void show(@PathVariable("code") String code,
HttpServletRequest request, HttpServletResponse response)
throws ConfigurationException, BarcodeException, IOException {
DefaultConfiguration cfg = new DefaultConfiguration("barcode");
DefaultConfiguration child = new DefaultConfiguration("datamatrix"); //code128
DefaultConfiguration attr;
//attr= new DefaultConfiguration("height");
//attr.setValue("10");
cfg.addChild(child);
//child.addChild(attr);
attr = new DefaultConfiguration("module-width");
attr.setValue("0.6");
child.addChild(attr);
int orientation = 0;
int resolution = 300;
BarcodeUtil util = BarcodeUtil.getInstance();
BarcodeGenerator gen = util.createBarcodeGenerator(cfg);
ByteArrayOutputStream bout = new ByteArrayOutputStream(4096);
BitmapCanvasProvider bitmap = new BitmapCanvasProvider(bout,
MimeTypes.MIME_JPEG, resolution, BufferedImage.TYPE_BYTE_BINARY,
false, orientation);
gen.generateBarcode(bitmap,code);
try {
bitmap.finish();
} catch (IOException e) {
} finally {
try {
bout.close();
} catch (IOException e) {
}
}
response.setContentType(MimeTypes.MIME_JPEG);
response.setContentLength(bout.size());
response.getOutputStream().write(bout.toByteArray());
response.getOutputStream().flush();
}
}
通过zxing生成
package gov.rsj.controller;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
/**
* @author fox
* @date 2012-3-22 下午3:12:33
* @version 1.0
* @description QRCODE 条形码 需要javase.jar和core.jar两个包
*/
@Controller
@RequestMapping("/qrbar/{code}")
public class QrBarCodeController {
@RequestMapping(method = RequestMethod.GET)
public void show(@PathVariable("code") String code,
HttpServletRequest request, HttpServletResponse response){
QRCodeWriter writer = new QRCodeWriter();
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
BitMatrix bitMatrix = null;
try {
bitMatrix = writer.encode(code, BarcodeFormat.QR_CODE, 300, 300);
MatrixToImageWriter.writeToStream(bitMatrix, "jpeg", response.getOutputStream());
response.getOutputStream().flush();
response.getOutputStream().close();
} catch (WriterException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
分享到:
相关推荐
java生成二维码QRCode简单认识(推荐使用jquery方式生成)
Java使用QRCode.jar生成二维码 附带DEMO免费下载
1.通过QRCode.jar包生成二维码,可设置二维码图片格式,二维码图片存放路径,二维码尺寸,二维码颜色 2.二维码扫描内容分为两种,1种为链接式,如:www.zdkc.com,通过链接展示访问的内容,1种为json数据展示,通过...
java工具实现类-根据网站链接url,生成二维码图片,存放本地目录
本代码为二维码生成和解析的Java实现代码,包括三个类和一个QRCode的jar包(一个jar包用于生成二维码,一个jar包用于读取二维码尤其用于读取的jar包不好下载,所以就一起放进来了,方便大家学习使用),一个生成...
java生成二维码,java将二维码转换成base64
Java后台生成二维码工具类
java 使用zxing生成二维码(带logo和文字说明)已经封装 使用起来很方便 下载下来直接调用传入参数就可以
QRcode生成、解析二维码项目与所有jar,注意,是包含生成、解析二维码!
该资源为java生成二维码,可调整二维码大小,排版,密度,设置图片头像
Java用qrcode生成二维码,同zxing生成二维码技术,,,
java使用qrCode生成二维码实例中间带logo.zip
一个java生成二维码的例子,可以直接生成显示到页面,也可以生成保存在硬盘上,
二维码生成的java代码包,主要支持QRCODE,ACTEC等国外标准的二维码,适合咱们开发系统使用,生成二维码后就可以利用手机 手持设备开发读取解码系统了。
java生成二维码,中间带logo,logo居中,完美实现,logo大小可调整。
https://blog.csdn.net/my_batis/article/details/111193350 效果图查看地址 测试 连接: http://localhost:8086/musice/qrcode
这个压缩包包含了生成二维码所需的QRCode.jar包和生成二维码所需要的Java代码。主要用于后台生成二维码。简单方便
java生成二维码所需要的jar包,包含qrcode.jar和qrcode_swetake.jar,内含使用方法。
最详细,真实的java生成二维码工具类,如果有问题请私信我
关于什么是二维码,如何生成二维码;往上一大堆的文章;像Java需要引入第三方的包,或者某些网页都要调用地方的URL来生成! 这样看起来挺麻烦的~ 实际上在oracle , 无须第三方的Jar包,也无需要第三方的二维码服务!直接...