samedi 4 juillet 2020

render BufferedImage to html Java - pippo.ro webframework

I have the following code:

GET("/image", routeContext -> {
            try {
                BufferedImage barcode = Utils.generateEAN13BarcodeImage3("12345678901");
                File outputfile = new File("saved.png");
                ImageIO.write(barcode, "png", outputfile);

                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ImageIO.write(barcode, "png", baos);
                byte[] imageData = baos.toByteArray();

                routeContext.send(barcode );
            } catch (Exception e) {
                e.printStackTrace();
            }
        });

I use the Pippo.ro library for all the "webserver-stuff".
How do I "render" the BufferedImage (Barcode) as an image?
I mean, i want to "get" an image if i call the url: 127.0.0.1/image

if is use routeContext.send(barcode ); I get an image but the browser downloads it directly. I want it do be "displayed"/rendered and not directly downloaded!

Thanks




Aucun commentaire:

Enregistrer un commentaire