Java Production Barcode Code

Source: Internet
Author: User

The first method:

Public String Getjbarcode (String barCode) {

String Barcodepath = "";

Try {

Jbarcode Localjbarcode = new jbarcode (Ean13encoder.getinstance (), Widthcodedpainter.getinstance () , Ean13textpainter.getinstance ());

BufferedImage localbufferedimage = localjbarcode. Createbarcode (barCode);

Savetojpeg (localbufferedimage, barCode+". jpg");

}

Catch (Exception localexception) {

localexception. Printstacktrace ();

}

return barcodepath;

}

Static void savetojpeg (bufferedimage parambufferedimage, String paramstring) {

SaveToFile (parambufferedimage, paramstring, "JPEG");

}

Static void savetofile (bufferedimage parambufferedimage, String paramString1, String ParamString2) {

Try {

FileOutputStream Localfileoutputstream = new fileoutputstream ("/users/mac/user/" + ParamString1);

Imageutil.encodeandwrite (parambufferedimage, paramString2, Localfileoutputstream, 96, 96);

Localfileoutputstream. Close ();

}

Catch (Exception localexception) {

localexception. Printstacktrace ();

}

}





The second method:

Public Static void Main (string[] paramarrayofstring)

{

Try

{

Jbarcode Localjbarcode = new jbarcode (Ean13encoder.getinstance (), widthcodedpainter.getinstance (), ean13textpainter.getinstance ());

//Generate. European Commodity Barcode (=european article number)

//Here we use the book barcode

String str = "693320970002";

BufferedImage localbufferedimage = localjbarcode. Createbarcode (str);

Savetogif (localbufferedimage, "Ean13.gif");

localjbarcode. Setencoder (code39encoder. getinstance ());

localjbarcode. Setpainter (wideratiocodedpainter. getinstance ());

localjbarcode. Settextpainter (baselinetextpainter. getinstance ());

localjbarcode. Setshowcheckdigit (false);

//xx

str = "JBARCODE-39";

Localbufferedimage = Localjbarcode. Createbarcode (str );

Savetopng (localbufferedimage, "Code39.png");

}

Catch (Exception localexception)

{

localexception. Printstacktrace ();

}

}

Static void savetojpeg (bufferedimage parambufferedimage, String paramstring)

{

SaveToFile (Parambufferedimage, paramstring, "JPEG");

}

Static void savetopng (bufferedimage parambufferedimage, String paramstring)

{

SaveToFile (Parambufferedimage, paramstring, "png");

}

Static void savetogif (bufferedimage parambufferedimage, String paramstring)

{

SaveToFile (Parambufferedimage, paramstring, "gif");

}

Static void SaveToFile (bufferedimage parambufferedimage, string paramString1, string paramString2)

{

Try

{

FileOutputStream Localfileoutputstream = new fileoutputstream ("/users/mac/user" + ParamString1);

Imageutil.encodeandwrite (Parambufferedimage, paramString2,  Localfileoutputstream, 96, 96);

localfileoutputstream. Close ();

}

Catch (Exception localexception)

{

localexception. Printstacktrace ();

}

}


This article is from the "12344888" blog, please be sure to keep this source http://12354888.blog.51cto.com/12344888/1877899

Java Production Barcode Code

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.