Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Graalvm native image #45

Open
SingingBush opened this issue Feb 23, 2024 · 1 comment
Open

Support Graalvm native image #45

SingingBush opened this issue Feb 23, 2024 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@SingingBush
Copy link
Owner

I've done some testing with Quarkus Native and found that after building a native executable there are runtime issues. It's worth investigating a little further as it may well be possible to get things working with some configuration properties

@SingingBush
Copy link
Owner Author

I've made some changes to barcode4j that enable the library to be used in a native build. However it does require manually registering an instance of ImageIOBitmapEncoder (something that was previously done only by classname).

BitmapEncoderRegistry.register(new ImageIOBitmapEncoder(), 0);

example code is along the lines of:

final Code39Bean barcode = new Code39Bean();
barcode.setWideFactor(3);
barcode.setModuleWidth(UnitConv.in2mm(1.0f / dpi));
barcode.doQuietZone(false);

final File outputFile = new File(String.format("out-%s.bmp", Instant.now().getEpochSecond()));

try (final OutputStream out = new FileOutputStream(outputFile)) {

    BitmapEncoderRegistry.register(new ImageIOBitmapEncoder(), 0); // required changes in barcode4j

    final BitmapCanvasProvider canvas = new BitmapCanvasProvider(out, MimeTypes.MIME_JPEG, dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0);

    //Generate the barcode
    barcode.generateBarcode(canvas, "0123456789");

    //Signal end of generation
    canvas.finish();
} catch (final IOException e) {
    log.error("IO exception while generating barcode", e);
    throw new RuntimeException(e);
}

There are a few more areas that will require changes as well (see todo comments in e1e143e).

Once these issues are resolved and more testing has been done then using barcode4j within a Quarkus native build should be straight forward.

@SingingBush SingingBush added this to the 2.3.0 milestone Jul 17, 2024
@SingingBush SingingBush added the enhancement New feature or request label Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant