我看到你提问了java生成条形码的问题,请问你是用什么生成的?我现在也有这个问题
我现在20位以下的没问题,但是20位以上的条码生成出来打印在条码纸上它变得很小,请问怎么放大它...
我现在20位以下的没问题,但是20位以上的条码生成出来打印在条码纸上 它变得很小,请问怎么放大它
展开
1个回答
展开全部
public static final int height = 226 + 2 * border; // 8cm + border
public static final int width = 212 + 2 * border; // 7.5cm + border
private static final int rate = 3; // 条码宽条与窄条宽度之比
private static int m_nNarrowWidth = 10; // 窄条的宽度像素数
private static int m_nImageHeight = 250; // 条码的高度像素数
// =========添加条形码begin===================
Barcode128 barcode128 = new Barcode128();
String strCodes = shipment.getPostalReferenceNo();
barcode128.setCode(strCodes);
int nImageWidth = (strCodes.length() * (3 * rate + 7) * m_nNarrowWidth);
java.awt.image.BufferedImage bufferedImage = new BufferedImage(
nImageWidth, m_nImageHeight + 13, BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) bufferedImage.getGraphics();
g.fillRect(0, 33, nImageWidth, 13);
java.awt.Image codeImg = barcode128.createAwtImage(Color.black,
Color.white);
g.drawImage(codeImg, 0, 0, nImageWidth, m_nImageHeight, null);
g.setColor(Color.BLUE);
g.dispose();
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "jpg", os);
Image img1 = Image.getInstance(os.toByteArray());
img1.setAlignment(Image.ALIGN_CENTER);
你试试
public static final int width = 212 + 2 * border; // 7.5cm + border
private static final int rate = 3; // 条码宽条与窄条宽度之比
private static int m_nNarrowWidth = 10; // 窄条的宽度像素数
private static int m_nImageHeight = 250; // 条码的高度像素数
// =========添加条形码begin===================
Barcode128 barcode128 = new Barcode128();
String strCodes = shipment.getPostalReferenceNo();
barcode128.setCode(strCodes);
int nImageWidth = (strCodes.length() * (3 * rate + 7) * m_nNarrowWidth);
java.awt.image.BufferedImage bufferedImage = new BufferedImage(
nImageWidth, m_nImageHeight + 13, BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) bufferedImage.getGraphics();
g.fillRect(0, 33, nImageWidth, 13);
java.awt.Image codeImg = barcode128.createAwtImage(Color.black,
Color.white);
g.drawImage(codeImg, 0, 0, nImageWidth, m_nImageHeight, null);
g.setColor(Color.BLUE);
g.dispose();
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "jpg", os);
Image img1 = Image.getInstance(os.toByteArray());
img1.setAlignment(Image.ALIGN_CENTER);
你试试
来自:求助得到的回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询