/** * Output a BufferedImage object into the response outputstream. Once this method has been called, no further action * is possible. Users should set {@code $context.setFinished(true)} to avoid template output. The image is served as * image/jpeg. * * @param image the BufferedImage to output * @throws java.io.IOException if the output fails * @since 1.3 Milestone 2 */ public void outputImage(BufferedImage image) throws IOException { OutputStream ostream = getXWikiContext().getResponse().getOutputStream(); Utils.getComponent(ImageProcessor.class).writeImage(image, "image/jpeg", (float) 0.8, ostream); ostream.flush(); }
private void resizeImageToAttachment(InputStream imageFileInputStream, int width, int height, XWikiAttachment outputAttachment) throws IOException { OutputStream attachmentOutputStream = null; try { Image originalImage = imageProcessor.readImage(imageFileInputStream); RenderedImage resizedImage = imageProcessor.scaleImage(originalImage, width, height); attachmentOutputStream = outputAttachment.getAttachment_content().getContentOutputStream(); imageProcessor.writeImage(resizedImage, "image/png", 1.0f, attachmentOutputStream); } finally { // Close the attachment output stream since we are done writing to it. if (attachmentOutputStream != null) { IOUtils.closeQuietly(attachmentOutputStream); } } } }
this.imageProcessor.writeImage(shrunkImage, attachment.getMimeType(context), quality, bout);