Hi,
Here is a code we use to generate a PNG image with barcode4j.
public static NSData code128ImgData(String in_value, double in_height,
boolean in_showHumanMsg) throws IOException {
ByteArrayOutputStream l_os = new ByteArrayOutputStream();
Code128Bean bean = new Code128Bean();
final int dpi = 300;
boolean antiAlias = false;
int orientation = 0;
// Configure the barcode generator
bean.setModuleWidth(UnitConv.in2mm(5.5f / dpi));
bean.doQuietZone(false);
bean.setFontSize(UnitConv.pt2mm(10D));
bean.setBarHeight(UnitConv.pt2mm(in_height));
if (in_showHumanMsg == false) {
bean.setMsgPosition(HumanReadablePlacement.HRP_NONE);
}
BitmapCanvasProvider canvas = new BitmapCanvasProvider(dpi,
BufferedImage.TYPE_BYTE_BINARY, antiAlias, orientation);
bean.generateBarcode(canvas, in_value);
// Signal end of generation
canvas.finish();
// Get generated bitmap
BufferedImage symbol = canvas.getBufferedImage();
int width = symbol.getWidth();
int height = symbol.getHeight();
// Add padding
int padding = 2;
width += 2 * padding;
height += 3 * padding;
BufferedImage bitmap = new BufferedImage(width, height,
BufferedImage.TYPE_BYTE_BINARY);
Graphics2D g2d = (Graphics2D) bitmap.getGraphics();
g2d.setBackground(Color.white);
g2d.setColor(Color.black);
g2d.clearRect(0, 0, bitmap.getWidth(), bitmap.getHeight());
// Place the barcode symbol
AffineTransform symbolPlacement = new AffineTransform();
symbolPlacement.translate(padding, padding);
g2d.drawRenderedImage(symbol, symbolPlacement);
g2d.dispose();
try {
String mime = "image/png";
final BitmapEncoder encoder =
BitmapEncoderRegistry.getInstance(mime);
encoder.encode(bitmap, l_os, mime, dpi);
} catch (UnsupportedOperationException e) {
log.warn("Exception occurred", e);
l_os = null;
}
return l_os != null ? new NSData(l_os.toByteArray()) : null;
}
Stéphan
Le 13 mai 2013 à 08:19, Jake Bearkley <[email protected]> a écrit :
>
> Hi All
>
> Does anyone have any code snippets or examples to show a barcode being
> generated and printed
>
> And then a barcode reader used to input into their application?
>
> Thanks in advance
> Bearko
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list ([email protected])
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/s.mertz%40improve.fr
>
> This email sent to [email protected]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]