Dynamic Image in Jasper Report
jrxml content <image> <reportElement x="5" y="5" width="200" height="90"/> <imageExpression class=" java.awt.Image "><![CDATA[$P{logo}]]></imageExpression> </image> Java Code to convert image from URL into BufferedImage URL url = new URL("http://localhost/image/image.jpg"); // Read the image ... InputStream inputStream = url.openStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int n = 0; while (-1 != (n = inputStream.read(buffer))) { baos.write(buffer, 0, n); } baos.flush(); byte[] imageInByte = baos.toByteArray(); baos.close(); // convert byte array back to BufferedImage InputStream in = new ByteArrayInputStream(imageInByte); BufferedImage
Comments
Post a Comment