public void outputtingBarcodeAsAJPEGImage() throws BarcodeException {
// Always get a Barcode from the BarcodeFactory
Barcode barcode = BarcodeFactory.createCode128B("http://zeroliu.blogdriver.com/");
try {
// We need an output stream to write the image to...
FileOutputStream fos = new FileOutputStream("mybarcode.jpg");
// Let the barcode image handler do the hard work
BarcodeImageHandler.outputBarcodeAsJPEGImage(barcode, fos);
} catch (IOException e) {
// Error handling here
}
}
//下面的也是:
java 生成条形码
package com.imgread;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class Code {
/*protected void Page_Load(object sender, EventArgs e) {
Response.Write(bar_code("www.sosuo8.com", 100, 1, 2));
}*/
public String bar_code(Object str, int ch, int cw, int type_code) {
/*
* str:输入的字符串.
* ch:要显示条形码的高度.
* cw:要显示条形码的宽度.
* type_code:代码类型.
*/
String strTmp = str.toString();
String code = strTmp;
// ToLower()将string转化成小写形式的副本,返回是使用指定区域的性的大小写规则。
strTmp = strTmp.toLowerCase();
int height = ch;
int width = cw;
//将传入的参数进行转化。
/*strTmp = strTmp.replace("0", "_|_|__||_||_|");
strTmp = strTmp.replace("1", "_||_|__|_|_||");
strTmp = strTmp.replace("2", "_|_||__|_|_||");
strTmp = strTmp.replace("3", "_||_||__|_|_|");
strTmp = strTmp.replace("4", "_|_|__||_|_||");
strTmp = strTmp.replace("5", "_||_|__||_|_|");
strTmp = strTmp.replace("7", "_|_|__|_||_||");
strTmp = strTmp.replace("6", "_|_||__||_|_|");
strTmp = strTmp.replace("8", "_||_|__|_||_|");
strTmp = strTmp.replace("9", "_|_||__|_||_|");
strTmp = strTmp.replace("a", "_||_|_|__|_||");
strTmp = strTmp.replace("b", "_|_||_|__|_||");
strTmp = strTmp.replace("c", "_||_||_|__|_|");
strTmp = strTmp.replace("d", "_|_|_||__|_||");
strTmp = strTmp.replace("e", "_||_|_||__|_|");
strTmp = strTmp.replace("f", "_|_||_||__|_|");
strTmp = strTmp.replace("g", "_|_|_|__||_||");
strTmp = strTmp.replace("h", "_||_|_|__||_|");
strTmp = strTmp.replace("i", "_|_||_|__||_|");
strTmp = strTmp.replace("j", "_|_|_||__||_|");
strTmp = strTmp.replace("k", "_||_|_|_|__||");
strTmp = strTmp.replace("l", "_|_||_|_|__||");
strTmp = strTmp.replace("m", "_||_||_|_|__|");
strTmp = strTmp.replace("n", "_|_|_||_|__||");
strTmp = strTmp.replace("o", "_||_|_||_|__|");
strTmp = strTmp.replace("p", "_|_||_||_|__|");
strTmp = strTmp.replace("r", "_||_|_|_||__|");
strTmp = strTmp.replace("q", "_|_|_|_||__||");
strTmp = strTmp.replace("s", "_|_||_|_||__|");
strTmp = strTmp.replace("t", "_|_|_||_||__|");
strTmp = strTmp.replace("u", "_||__|_|_|_||");
strTmp = strTmp.replace("v", "_|__||_|_|_||");
strTmp = strTmp.replace("w", "_||__||_|_|_|");
strTmp = strTmp.replace("x", "_|__|_||_|_||");
strTmp = strTmp.replace("y", "_||__|_||_|_|");
strTmp = strTmp.replace("z", "_|__||_||_|_|");
strTmp = strTmp.replace("-", "_|__|_|_||_||");
strTmp = strTmp.replace("*", "_|__|_||_||_|");
strTmp = strTmp.replace("/", "_|__|__|_|__|");
strTmp = strTmp.replace("%", "_|_|__|__|__|");
strTmp = strTmp.replace("+", "_|__|_|__|__|");
strTmp = strTmp.replace(".", "_||__|_|_||_|");*/
strTmp = strTmp.replace("0", "_|__||_||_");
strTmp = strTmp.replace("1", "|_|__|_|_|");
strTmp = strTmp.replace("2", "_||__|_|_|");
strTmp = strTmp.replace("3", "|_||__|_|_");
strTmp = strTmp.replace("4", "_|__||_|_|");
strTmp = strTmp.replace("5", "|_|__||_|_");
strTmp = strTmp.replace("7", "_|__|_||_|");
strTmp = strTmp.replace("6", "_||__||_|_");
strTmp = strTmp.replace("8", "|_|__|_||_");
strTmp = strTmp.replace("9", "_||__|_||_");
strTmp = strTmp.replace("a", "|_|_|__|_|");
strTmp = strTmp.replace("b", "_||_|__|_|");
strTmp = strTmp.replace("c", "|_||_|__|_");
strTmp = strTmp.replace("d", "_|_||__|_|");
strTmp = strTmp.replace("e", "|_|_||__|_");
strTmp = strTmp.replace("f", "_||_||__|_");
strTmp = strTmp.replace("g", "_|_|__||_|");
strTmp = strTmp.replace("h", "|_|_|__||_");
strTmp = strTmp.replace("i", "_||_|__||_");
strTmp = strTmp.replace("j", "_|_||__||_");
strTmp = strTmp.replace("k", "|_|_|_|__|");
strTmp = strTmp.replace("l", "_||_|_|__|");
strTmp = strTmp.replace("m", "|_||_|_|__");
strTmp = strTmp.replace("n", "_|_||_|__|");
strTmp = strTmp.replace("o", "|_|_||_|__");
strTmp = strTmp.replace("p", "_||_||_|__");
strTmp = strTmp.replace("r", "|_|_|_||__");
strTmp = strTmp.replace("q", "_|_|_||__|");
strTmp = strTmp.replace("s", "_||_|_||__");
strTmp = strTmp.replace("t", "_|_||_||__");
strTmp = strTmp.replace("u", "|__|_|_|_|");
strTmp = strTmp.replace("v", "__||_|_|_|");
strTmp = strTmp.replace("w", "|__||_|_|_");
strTmp = strTmp.replace("x", "__|_||_|_|");
strTmp = strTmp.replace("y", "|__|_||_|_");
strTmp = strTmp.replace("z", "__||_||_|_");
strTmp = strTmp.replace("-", "__|_|_||_|");
strTmp = strTmp.replace("*", "__|_||_||_");
strTmp = strTmp.replace("/", "__|__|_|__");
strTmp = strTmp.replace("%", "_|__|__|__");
strTmp = strTmp.replace("+", "__|_|__|__");
strTmp = strTmp.replace(".", "|__|_|_||_");
//strTmp = strTmp.replace("_", "<span style='height:" + height + ";width:" + width + ";background:#FFFFFF;'></span>");
//strTmp = strTmp.replace("|", "<span style='height:" + height + ";width:" + width + ";background:#165829;'></span>");
String strTmp1 = strTmp.substring(0, strTmp.length()/2);
String strTmp2 = strTmp.substring(strTmp.length()/2, strTmp.length());
strTmp1 = strTmp1.replace("_", "<span style='height:" + height + ";width:" + width + ";background:#FFFFFF;'></span>");
strTmp1 = strTmp1.replace("|", "<span style='height:" + height + ";width:" + width + ";background:#000000;'></span>");
strTmp2 = strTmp2.replace("_", "<span style='height:" + height + ";width:" + width + ";background:#FFFFFF;'></span>");
strTmp2 = strTmp2.replace("|", "<span style='height:" + height + ";width:" + width + ";background:#0068b7;'></span>");
strTmp = strTmp1 + strTmp2;
if (type_code == 1) {
return strTmp + "<BR>" + code;
} else {
return strTmp;
}
}
public static void main(String[] arg){
SimpleDateFormat setDateFormat = new SimpleDateFormat("yy/MM/dd kk:mm:ss");
Date time = new Date();
String temp = setDateFormat.format(time.getTime()).replace("/", "").replace(":", "").replace(" ", "");
Code code = new Code();
Object co = code.bar_code(temp, 1, 1, 1);
System.out.println(co);
}
}
分享到:
相关推荐
Java生成条码保存在pdf上例子(亲测),并且附赠 水印添加。
JAVA生成条码什么格式的都有 JAVA生成条码
目前比较通用的用Java实现条形码打印的集成插件主要有:barbecue和barcode4j. 但是用barbecue,条形码可以显示出来,可是下面对应数字却不能显示出来,当然可以自己手动加上去,不过那就不是一张图片里面的了,并且...
java生成条形码的Demo 可以直接就运行,里面还有说明
java的条形码生成工具,报表开发中会使用到,本人使用感觉比较好用
java生成条码.rar,java生成条码.rar,java生成条码.rar
java实现条形码二维码生成含文字标签信息
Java三种生成条形码的源码 1、用barcode4j方式生成 2、用jbarcode方式生产成 3、google-zxing方式生成,但该方式较不方便,添加条形码数字叫复杂
maven项目首先要导入pom资源 <groupId>net.sf.barcode4j</groupId> <artifactId>barcode4j-light <version>2.0 </dependency>
二维码、条形码生成工具类(java),根据内容转换成二维码或者条形码并输出图片
忘记这个资源是在哪里下载的了,非常好用,感谢该代码作者的奉献。里面有生成条形码的demo和jar包,可以直接进行测试,也可以集成项目里,修改成自己想要的接口。
使用Graphics2D和Zxing生成物流打印单,生成条形码和二维码
按公司的要求自己测试好久才整出来的,好用,给大家共享一下,有什么问题可以问我
Java生成条形码的方案 -- barcode4j、zxing barcode4j开源Java条形码生成库。支持多种编码格式,比如:code-39,code-128等 http://barcode4j.sourceforge.net/ zxing是由google开源的1D/2D编解码类库。目标是能够对...
老外用java写的生成条形码的包 自己用的时候最好只生成条形码 不要显示条形码对应的内容 因为有一条黑线