0
点赞
收藏
分享

微信扫一扫

JAVA生成商品条形码(一维码),等比例放大/缩小图象


利用:jbarcode.jar轻松生成各种条形码


http://sourceforge.net/projects/jbcode/

本人亲手扫描,成功可用!

	/*
02	2. * To change this template, choose Tools | Templates
03	3. * and open the template in the editor.
04	4. */ 
05	 
06	package com.zhilong.juyuansu.test; 
07	 
08	import java.awt.image.BufferedImage; 
09	import java.io.FileOutputStream; 
10	import org.jbarcode.JBarcode; 
11	import org.jbarcode.encode.EAN8Encoder;
12	import org.jbarcode.paint.EAN8TextPainter;
13	import org.jbarcode.paint.WidthCodedPainter; 
14	import org.jbarcode.util.ImageUtil; 
15	/**
16	 * 2012-05-28
17	 * <a href="http://my.oschina.net/arthor" target="_blank" rel="nofollow">@author</a> 郏高阳
18	 * 支持EAN13, EAN8, UPCA, UPCE, Code 3 of 9, Codabar, Code 11, Code 93, Code 128, MSI/Plessey, Interleaved 2 of PostNet等
19	 *
20	 */ 
21	public class OneBarcodeUtil { 
22	 
23	    public static void main(String[] paramArrayOfString) { 
24	        try { 
25	            JBarcode localJBarcode = new JBarcode(EAN8Encoder.getInstance(),WidthCodedPainter.getInstance(),EAN8TextPainter.getInstance()); 
26	            String str = "2219644"; 
27	            BufferedImage localBufferedImage = localJBarcode.createBarcode(str); 
28	             
29	            saveToGIF(localBufferedImage, "EAN8.jpg");
30	        } 
31	        catch (Exception localException) { 
32	            localException.printStackTrace(); 
33	        } 
34	    } 
35	 
36	    static void saveToJPEG(BufferedImage paramBufferedImage, String paramString) { 
37	        saveToFile(paramBufferedImage, paramString, "jpeg"); 
38	    } 
39	 
40	    static void saveToFile(BufferedImage paramBufferedImage, String paramString1, String paramString2) { 
41	        try { 
42	            FileOutputStream localFileOutputStream = new FileOutputStream("C:\\Users\\Administrator\\Desktop/" + paramString1); 
43	            ImageUtil.encodeAndWrite(paramBufferedImage, paramString2, localFileOutputStream, 96, 96); 
44	            localFileOutputStream.close(); 
45	        } 
46	        catch (Exception localException) { 
47	            localException.printStackTrace(); 
48	        } 
49	    } 
50	}

 

JAVA生成商品条形码(一维码),等比例放大/缩小图象_等比例缩放

格式为:EAN8条形码!(EAN8格式为7位数组成,最后以为随机编号!拥有60%的市场)


等比例放大图片(小做修改就可以缩小)

 

01	/**
02	     * 等比例放大图象
03	     *
04	     * @param imgUrl 图像路径
05	     * @param resultImgUrl 放大后的存放路径
06	     * @param scale 放大倍数
07	     * @throws IOException
08	     */
09	    static void scale(String imgUrl, String resultImgUrl, int scale)
10	            throws IOException {
11	        BufferedImage src = ImageIO.read(new File(imgUrl));
12	        int width = src.getWidth();
13	        int height = src.getHeight();
14	 
15	        width = width * scale;
16	        height = height * scale;
17	 
18	        Image image = src.getScaledInstance(width, height, Image.SCALE_DEFAULT);
19	        BufferedImage tag = new BufferedImage(width, height,
20	                BufferedImage.TYPE_INT_RGB);
21	        Graphics g = tag.getGraphics();
22	        g.drawImage(image, 0, 0, null);
23	        g.dispose();
24	        ImageIO.write(tag, "JPEG", new File(resultImgUrl));
25	    }

举报

相关推荐

0 条评论