Caio ragazzi,
devo stampare dei codici a barre EAN13 su un etichetta da 30mm x 25mm.
Ho provato sia la libreria "barbecue" che quella "barcodelib", ma nel rimpicciolire il barcode anche con BufferImage mi esce tutto sgranato e non viene letto dal lettore .
ecco il codice che ho usato
codice://BarcodeLib Linear barcode = new Linear(); barcode.setType(Linear.EAN13); // barcode data to encode // should be 12 digits barcode.setData(ean.substring(0, 12)); // unit of measure for X, Y, LeftMargin, RightMargin, TopMargin, BottomMargin barcode.setUOM(Linear.UOM_PIXEL); // barcode module width in pixel barcode.setX(0f); // barcode module height in pixel barcode.setY(50f); barcode.setLeftMargin(0f); barcode.setRightMargin(0f); barcode.setTopMargin(0f); barcode.setBottomMargin(0f); // barcode image resolution in dpi barcode.setResolution(300); // disply human readable text under the barcode barcode.setShowText(true); // human reable text font style barcode.setTextFont(new Font("Arial", 0, 10)); // ANGLE_0, ANGLE_90, ANGLE_180, ANGLE_270 barcode.setRotate(Linear.ANGLE_0); //barcode.renderBarcode("c://ean131.gif"); try { BufferedImage img = barcode.renderBarcode(); // g.drawImage(img, 15, 30, 75,60, null); g.drawImage(img,15,30,null); } catch (Exception e) {e.printStackTrace();}codice://BARBECUE try { barcode.setBarHeight(51); barcode.setBarWidth(1); barcode.setFont(new Font("Arial", Font.BOLD, 5)); //barcode.setFont(new Font("Arial", Font.BOLD, 10)); barcode.draw(g, 10, 35); } catch (OutputException e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();} /* problema testo e non legge il barcode barcode.setBarHeight(50); barcode.setBarWidth(1); barcode.setFont(new Font("Arial", Font.PLAIN, 5)); try { // System.out.println("barcode w "+barcode.getWidth()+" h "+barcode.getHeight()); g.drawImage(BarcodeImageHandler.getImage(barcode),15,30,barcode.getWidth()-40,barcode.getHeight(),Color.WHITE,null); // 226/3 180/3 } catch (OutputException e) {e.printStackTrace();}

Rispondi quotando