开发者

Java barcode query

Im trying to code a scenario wherein there is a routine that takes in input as the data to encode and other paramet开发者_JAVA技巧ers like barcode height and width. The routine then encodes the barcode and converts the data into the barcode encoding form and returns this as a he string.

I have tried out a few external libraries and have found them to only return an image(PNG,GIF) but Im looking at getting the resulting hex format of the barcode image for the data that I feed to the routing.

Also, it would be great if the result can be achieved through relatively inexpensive operations and the process of accomplishing the same being stable and not buggy.

Anyone know of any external library of any pointers on how this can be achieved ?


Let's define 3 steps for the barcode creation:

  1. Fit all the data in a string. (i.e. using fixed width for each item or using separator characters).
  2. Convert the string to the barcode charset.
  3. Output the barcode image using the barcode simbology.

If I undestood correctly, you want the result of step 2. Usually this isn't too difficult, but first you need to define which barcode format are you using.


Your best bet is to convert each barcode character into a PNG represented in base64. Then it is just a matter of sticking with the rules of the symbology and stringing the "images" together. Here's an example:

<img alt="104,{Start B}" title="104,{Start B}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AC3gAT0BDuLeG4IAAAAASUVORK5CYII=" width="10" height="30"><img alt=" 51,A:{S},B:{S}" title=" 51,A:{S},B:{S}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ACLgAScBA3yI80wAAAAASUVORK5CYII=" width="10" height="30"><img alt=" 65,A:{SOH},B:{a}" title=" 65,A:{SOH},B:{a}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AGngAbUBSuiAnEkAAAAASUVORK5CYII=" width="10" height="30"><img alt=" 77,A:{CR},B:{m}" title=" 77,A:{CR},B:{m}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AAigALMAqe/ygasAAAAASUVORK5CYII=" width="10" height="30"><img alt=" 80,A:{DLE},B:{p}" title=" 80,A:{DLE},B:{p}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AFhgARMAuXYaS+YAAAAASUVORK5CYII=" width="10" height="30"><img alt=" 76,A:{FF},B:{l}" title=" 76,A:{FF},B:{l}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ADXgAU0BFkrGa3IAAAAASUVORK5CYII=" width="10" height="30"><img alt=" 69,A:{ENQ},B:{e}" title=" 69,A:{ENQ},B:{e}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AE3gAX0BLqHeudAAAAAASUVORK5CYII=" width="10" height="30"><img alt=" 85,A:{NAK},B:{u}" title=" 85,A:{NAK},B:{u}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AGGgAWUBAqmuuv8AAAAASUVORK5CYII=" width="10" height="30"><img alt="106,{Stop}" title="106,{Stop}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAABAQMAAAA/57ZEAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ADigARMA2dpJzT8AAAAASUVORK5CYII=" width="10" height="30">

This image stream displays the Code 128 barcode for the word "Sample" in a browser. If you need a true hexadecimal string, you can take the PNG image file and convert it. I guess I am uncertain what you mean by "feed to the routing".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜