How to make Bar Code Image in Javafx in Spring boot
Hello! guys! Welcome once again, In this lesson, we will learn how to make an image using Javafx. For example, we are going to make a project for a point of sale, and they want to get the barcodes of their products to use as a chip of price of the products, so for this purpose, we can make easily barcode using JavaFX like below:
public void printBarcode(ActionEvent actionEvent) throws WriterException { try{ Code128Bean code128Bean = new Code128Bean(); code128Bean.setHeight(15f); code128Bean.setModuleWidth(0.3); code128Bean.setQuietZone(10); code128Bean.doQuietZone(true); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); BitmapCanvasProvider bitmapCanvasProvider = new BitmapCanvasProvider(byteArrayOutputStream, "image/x-png", 300, BufferedImage.TYPE_BYTE_BINARY, false, 0); code128Bean.generateBarcode(bitmapCanvasProvider, reference.getText()); bitmapCanvasProvider.finish(); FileOutputStream fos = new FileOutputStream(productcombo.getSelectionModel().getSelectedItem().toString()+".png"); fos.write(byteArrayOutputStream.toByteArray()); reference.setText("Click on show Now"); fos.flush(); fos.close(); File file = new File(productcombo.getSelectionModel().getSelectedItem().toString()+".png"); Image image = new Image(file.toURI().toString()); imgplace.setImage(image); } catch (Exception e){ e.printStackTrace(); } } |
Wow, Excellent article. I think its must be helpful for us. Its really very effective and informative. Thanks for sharing your article. free bitcoin faucet | free bitcoin mining | free bitcoin earning sites | earn money online | freelancing sites
ReplyDelete