4

As far as I know, barcode as such can't be rotated (iReport doesn't have that property and neither does the Barbecue Barcode in a Java class). I've seen some examples, but they are incomplete and I don't understand how to use them, eg.:

public class BarbecueRenderer extends JRAbstractSvgRenderer
{

private boolean rotate;
private Barcode barcode = null;

public BarbecueRenderer(Barcode barcode) 
{
    this(barcode, false);
}

public BarbecueRenderer(Barcode barcode, boolean rotate) 
{
    this.barcode = barcode;
    this.rotate = rotate;
}

// What should I use as the grx and rectangle objects?
public void render(Graphics2D grx, Rectangle2D rectangle) 
{
    if (barcode != null) 
    {
        Graphics2D graphics = (Graphics2D) grx.create();
        graphics.translate(rectangle.getX(), rectangle.getY());
        if (rotate)
        {
            graphics.translate(barcode.getBounds().getHeight(), 0);
            graphics.rotate(Math.PI / 2);
        }
        barcode.draw(graphics, 0, 0);
    }
}
}

What I need is something like this:

 Barcode barcode = BarcodeFactory.createCode39("128", false);
 // rotate the barcode
 File f = new File ("c:\\barcode.jpg");
 BarcodeImageHandler.saveJPEG(barcode, f);
2

2 Answers 2

2

In jasper reports 4.0.2 you can simply edit the jrxml and add the rotation attribute to the jr:barbecue element.

<jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="Code128" drawText="true" checksumRequired="true" rotation="Right">

Possible values are any valid net.sf.jasperreports.engine.type.RotationEnum

1
  • Thank you, but I must use 2.0.2. In the end we dropped the idea.
    – Andrija
    Commented Aug 16, 2011 at 8:43
1

Try:

public BufferedImage rotate90DX(BufferedImage bi)
    {
        int width = bi.getWidth();
        int height = bi.getHeight();

        BufferedImage biFlip = new BufferedImage(height, width, bi.getType());

        for(int i=0; i<width; i++)
            for(int j=0; j<height; j++)
                biFlip.setRGB(height-1-j, width-1-i, bi.getRGB(i, j));

        return biFlip;
    }

As found at :

http://snippets.dzone.com/posts/show/2936

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.