0

私の場合、Barcode4j ライブラリを使用して生成した複数のバーコード (png) を 1 つの png ファイルに追加する必要があります。例が見つかりませんでした。また、それを解決する決心をすることもできませんでした。そのため、どんな助けでも大歓迎です。さて、通常の方法でバーコードを生成し (for を介して)、それらを bufferedImages のリスト (List) に収集します。次に、この画像を 1 つに接着する必要があります。私のコード:

 try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            BitmapCanvasProvider canvas = new BitmapCanvasProvider(baos, "image/x-png", 300, BufferedImage.TYPE_BYTE_BINARY, false, 0);
            List<BufferedImage> bufferedImageList = new ArrayList<>(); // list for bufferedImages
            for (int i = 0; i < barcodesList.size(); i++) {

                try {
                    Code128Bean code128 = new Code128Bean();
                    code128.setHeight(15f);
                    code128.setModuleWidth(0.3);
                    code128.setQuietZone(10);
                    code128.doQuietZone(true);

                    code128.generateBarcode(canvas, (String) barcodesList.get(i));
                    bufferedImageList.add(canvas.getBufferedImage()); // collect images of barcode in cicle
                    canvas.finish();

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            FileOutputStream fos = new FileOutputStream(barcodePath.toString());
            // to do smth to make one png from collected images
            fos.write(baos.toByteArray());
            fos.flush();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
4

1 に答える 1