【问题标题】:How can I rotate a barcode in Java/iReport?如何在 Java/iReport 中旋转条形码?
【发布时间】:2011-04-30 04:47:22
【问题描述】:

据我所知,条形码本身不能旋转(iReport 没有该属性,Java 类中的烧烤条形码也没有)。我看过一些例子,但它们不完整,我不明白如何使用它们,例如:

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);
    }
}
}

我需要的是这样的:

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

【问题讨论】:

标签: java jasper-reports barcode


【解决方案1】:

在 jasper 报告 4.0.2 中,您可以简单地编辑 jrxml 并将旋转属性添加到 jr:barbecue 元素。

<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">

可能的值是任何有效的net.sf.jasperreports.engine.type.RotationEnum

【讨论】:

  • 谢谢,但我必须使用2.0.2。最后我们放弃了这个想法。
【解决方案2】:

试试:

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;
    }

见于:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-22
    • 1970-01-01
    • 2019-11-22
    • 2013-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多