Untitled

mail@pastecode.io avatar
unknown
java
3 years ago
1.1 kB
3
Indexable
Never
    public static byte[] cargaImagenContent(String codigo) {

        if (codigo != null && codigo.length() > 1) {

            BufferedImage fotoContent = EngagemeFilesUtil
                    .cargarBufferedImage(AppGlobalConfig.getSchema() + "/"
                            + codigo);
            if (fotoContent != null) {
                ByteArrayOutputStream os = null;
                try {
                    // Reduce imagen a max 300 width
                    BufferedImage scaledImage = Scalr.resize(fotoContent, 300);
                    os = new ByteArrayOutputStream();
                    ImageIO.write(scaledImage, "png", os);
                    return os.toByteArray();
                } catch (IOException ex) {
                } finally {
                    if (os != null) {
                        try {
                            os.close();
                        } catch (IOException ex) {
                        }
                    }
                }
            }
        }
        return null;
    }