2010-10-25 64 views
4

據我所知,條形碼本身不能旋轉(iReport沒有該屬性,在Java類中也沒有Barbecue Barcode)。我見過一些例子,但它們是不完整的,我不知道如何使用它們,例如:如何在Java/iReport中旋轉條形碼?

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); 
+0

http://www.barcodelib.com/java_barcode/main.html – 2010-10-25 12:44:45

+0

忘了提,需要做的是免費的:) – Andrija 2010-10-25 12:53:28

回答

1

嘗試:

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

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

截至發現0

2

在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

+0

謝謝你,但我必須使用2.0.2。最後我們放棄了這個想法。 – Andrija 2011-08-16 08:43:02