Set Image component source from byte array

Hi,
I have generated byte-array (from BufferedImage). Any chance i can use it for Image component source?

Managed to do it by using com.haulmont.cuba.web.gui.components.WebStreamResource.

byte[] bytes = new byte[0];
        try {
            bytes = vectorDiagram.bytes();
        } catch (IOException e) {
            e.printStackTrace();
        }
WebStreamResource webStreamResource = new WebStreamResource();
        byte [] finalBytes = bytes;
        webStreamResource.setStreamSupplier(new Supplier<InputStream>() {
            @Override
            public InputStream get() {
                return new ByteArrayInputStream(finalBytes);
            }
        });
        img.setSource(webStreamResource);
3 Likes