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 pm 06:19:21 * @update: * @bolg: http://www.cnblogs.com/yuchuan/* @csdn: Http://blog.csdn.net/l_ly COS * @e-mail: [email protected] * @desc: * * @============================================= */public class TestBa            Rcode {/** * Generate product Barcode * * @param filePath * Product Barcode Image Storage Path: c://barcode//images//* * @param barcode *  Product Barcode: 13-bit * @param imgformat * Image format *           * @return Picture 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) {//Retu  RN null;//}try {bufferedimage bi = null;int len = jbarcode.length ();//Instantiate jbarcode//here three parameters, required fill jbarcode jbarcode13 = new Jbarcode (Ean13encoder.getinstance (), Widthcodedpainter.getinstance (), ean13textpainter.getinstance ());// Gets the first 12 bits of string barCode = jbarcode.substring (0, len-1);//gets to the check bit string code = jbarcode.substring (len-1, Len); String Checkcode = Jbarcode13.calcchecksum (BarCode), if (!code.equals (Checkcode)) {return ' EN-13 bar code The last check code is incorrect, should be: "+ ch Eckcode;} /* Most important is the setting here, if you understand the settings here is not a problem if the default setting, * then the setting is to generate a general barcode if not the default * setting, then you can set the *///size, size, Size jbarcode13.setxdimension (double.valueof (0.8). Doublevalue ());//bar code height Jbarcode13.setBarHeight (Double.valueof () Doublevalue ());//width ratio jbarcode13.setwideratio (double.valueof). Doublevalue ( );//whether to verify the last one, the default is Falsejbarcode13.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 two-dimensional code picture FileOutputStream fileoutputstream = null; String Imgpath = savepath + imgname + "." + imgformat;try {try {Savepath = Urldecoder.decode (Savepath, "UTF-8");} catch (U Nsupportedencodingexception 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, N), Fileoutputstream.close ();//return path to return imgpath;} catch (Exception e) {e.printstacktrace (); return null;}} /** * @param args * @throws invalidatribUteexception */public static void Main (string[] args) throws invalidatributeexception {String path = Testbarcode.createba RCode ("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:

  

Commodity 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.