• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Barcode example
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Barcode example


  • Subject: Re: Barcode example
  • From: Stéphan Mertz <email@hidden>
  • Date: Mon, 13 May 2013 10:57:46 +0200

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@hidden> 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@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Barcode example (From: Jake Bearkley <email@hidden>)

  • Prev by Date: Barcode example
  • Next by Date: Re: Troubles with com.webobjects.jspservlet
  • Previous by thread: Barcode example
  • Next by thread: Re: Barcode example
  • Index(es):
    • Date
    • Thread