Commodity barcode (Jbarcode) Java Edition (ii)

Source: Internet
Author: User

Afternoon open an afternoon meeting, in fact, meeting I listen to not go in, because today demon are particularly cold, work in the company waiting for Xiaoxifu one head, then take her to eat, eat dinner back home. When she was exercising, I began to slowly organize my own little blog.

--Preface

   

First of all, the purpose of writing this article is to improve the previous article everyone's question, although it is a simple function, but the last time is simply to make a function, and this time is to continue on the basis of the last function, do some optimization work, to their own life to add some records, put forward for everyone to learn, is also a way of learning. Every time after learning new things, it is necessary to comb, but also slowly become a part of life, feel this is a kind of self-habit.

I'm not going to say a lot of jar bags here.

Jbarcode, download the latest version: Jbarcode-0.2.8.jar, I basically go to the official website to download some things, some you do not know the answer, in the network basically have, so it is recommended that we all go to the official website to browse.

  

Here's the beginning of the results code, you can download the Utils tool class yourself and apply it to your project. (Note: according to their own needs to set the corresponding parameters can be)

  

Package Com.kinya.liuyc.barcode; Import Java.awt.image.BufferedImage; Import Java.io.File; Import Java.io.FileOutputStream;   Import java.io.UnsupportedEncodingException; Import Java.net.URLDecoder; Import Java.text.SimpleDateFormat;   Import Java.util.Date; Import Org.jbarcode.JBarcode; Import Org.jbarcode.encode.EAN13Encoder; Import org.jbarcode.encode.InvalidAtributeException; Import Org.jbarcode.paint.EAN13TextPainter; Import Org.jbarcode.paint.WidthCodedPainter;   Import Org.jbarcode.util.ImageUtil; /** * Easy to generate barcode (EN-13 code) * * @============================================= * * @author: LIUYC * @create: 2015-4-8 Afternoon 06:19:21 * @update: * @bolg: http://www.cnblogs.com/yuchuan/* @csdn: Http://blog.csdn.net/l_lycos * @e-mail: [E       Mail protected] * @desc: * * @============================================= */public class Testbarcode { /** * Generate Product Barcode * * @param filePath * Product Barcode Image Storage Path: c://barcode//images//* * @paRAM BarCode * Product Barcode: 13-bit * @param imgformat * Picture Format * * @return Chart Slice storage path + picture name + picture File type */public static string Createbarcode (String Savepath, String Jbarcode, String Imgfo         Rmat) {//checksum all omitted ...//if (Stringutils.isnotempty (Savepath)) {////return null;         }//if (Stringutils.isnotempty (Jbarcode)) {//return null;         }//if (Stringutils.isnotempty//(Imgformat)) {//return null;         }//if (Jbarcode.length ()!=13) {//return null;               } try {bufferedimage bi = null;               int len = Jbarcode.length ();                     Instantiate Jbarcode//Here are three parameters, necessary to fill jbarcode jbarcode13 = new Jbarcode (Ean13encoder.getinstance (),               Widthcodedpainter.getinstance (), ean13textpainter.getinstance ());     Get to top 12 bits        String BarCode = jbarcode.substring (0, len-1);             Gets the check bit String code = jbarcode.substring (len-1, Len);               String Checkcode = jbarcode13.calcchecksum (BarCode);             if (!code.equals (Checkcode)) {return "EN-13 barcode last Check code is incorrect, should be:" + checkcode; }/* Most important is the settings here, if you understand the settings here is not a problem if the default setting, * then the setting is to generate a generic barcode if it is not the default * Settings, then you can set the *//size, size, size jbarcode13.setxdimension (double.valueof (0.8)) according to your own needs. Doublev             Alue ());             Bar code Height Jbarcode13.setbarheight (double.valueof (+). Doublevalue ());             Width Rate Jbarcode13.setwideratio (double.valueof (). Doublevalue ());               Whether to verify the last one, the default is False Jbarcode13.setshowcheckdigit (true);               Generate two-dimensional code bi = jbarcode13.createbarcode (barCode); Define the picture name SimpleDateFormat SDF = new SimpleDateFormat ("YYyymmddhhmmss ");               String imgname = Sdf.format (New Date ()) + "_" + Jbarcode;             Save QR code picture FileOutputStream fileoutputstream = null;             String Imgpath = savepath + imgname + "." + Imgformat;                 try {try {Savepath = Urldecoder.decode (Savepath, "UTF-8");                     } catch (Unsupportedencodingexception uee) {uee.printstacktrace ();                 Savepath = "c://barcode//images//";                   } File Dirfile = new file (Savepath);                 if (!dirfile.exists ()) {dirfile.mkdirs ();             } FileOutputStream = new FileOutputStream (Imgpath);                 } catch (Exception e) {e.printstacktrace ();             return null;             } imageutil.encodeandwrite (Bi, Imgformat, FileOutputStream, 96, 96);               Fileoutputstream.close ();      return path       return imgpath;             } catch (Exception e) {e.printstacktrace ();         return null; }}/** * @param args * @throws invalidatributeexception */public static void Main (string[] A                 RGS) throws Invalidatributeexception {String path = Testbarcode.createbarcode ("d://test//", "6937748304340",           IMAGEUTIL.JPEG);       SYSTEM.OUT.PRINTLN (path);  }   }

  


                    

Through this time of optimization, let me know the importance of the source code, want to know something in-depth, you need to understand the internal, with learning knowledge to arm themselves, rookie study, Big Bird do not spray, just record, by the way to those who do not love their brains, if you like me this way, please click on the lower right corner of the recommendation,

Sleep, Xiaoxifu exercise also finished ...

Attached: Previous link Address: Commodity barcode (Jbarcode)

This article is copyrighted by the author and the blog Park is shared, welcome reprint, but without the author's consent must retain this paragraph, and in the article page obvious location to the original link

Original link: http://www.cnblogs.com/yuchuan/p/JBarcode2.html

If you think this article is good, may wish to recommend, let more readers get the harvest.
If you have any other ideas, may wish to leave a message, we all discuss together. Three people, there will be my teacher. Learn from each other and progress with each other!
If there is anything inappropriate or wrong with this article, please be sure to point it out in the comments to avoid fraught! Thank you very much for your generous comment!

Promote:

How to join us: QQ Group Subscription Number:


Product Barcode (Jbarcode) Java Edition (ii)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.