/** * Signals the encoder that you've finished sending pages for a multi-page image files. * @param context the context object you receive as return value to a previous call to * encodeMultiple() * @throws IOException In case of an I/O error */ public void finishMultiple(Object context) throws IOException { if (context == null) { throw new NullPointerException(); } Context c = (Context)context; // Get the encoding parameters. TIFFEncodeParam encodeParam = (TIFFEncodeParam)param; //write last image c.ifdOffset = encode(c.nextImage, encodeParam, c.ifdOffset, true); }
/** {@inheritDoc} */ public void writeImage(RenderedImage image, OutputStream out, ImageWriterParams params) throws IOException { TIFFEncodeParam encodeParams = createTIFFEncodeParams(params); TIFFImageEncoder encoder = new TIFFImageEncoder(out, encodeParams); encoder.encode(image); }
/** * Use Batik to save a TIFF file of the graph * * @param filename * name of the file to store the image into * @param image * to be stored */ public void saveTIFFWithBatik(String filename, BufferedImage image) { File outfile = new File(filename); OutputStream fos = createFile(outfile); if (fos == null) { return; } TIFFEncodeParam param = new TIFFEncodeParam(); TIFFImageEncoder encoder = new TIFFImageEncoder(fos, param); try { encoder.encode(image); } catch (IOException e) { JMeterUtils.reportErrorToUser("TIFFImageEncoder reported: "+e.getMessage(), "Problem creating image file"); } catch (Error e) { // NOSONAR TIFFImageEncoder uses Error to report runtime problems JMeterUtils.reportErrorToUser("TIFFImageEncoder reported: "+e.getMessage(), "Problem creating image file"); if (e.getClass() != Error.class){// NOSONAR rethrow other errors throw e; } } finally { JOrphanUtils.closeQuietly(fos); } }
/** * Encodes a RenderedImage as part of a multi-page file and writes the output to the * OutputStream associated with this ImageEncoder. * <p> * When you sent all pages, make sure you call finishMultiple() in the end. Otherwise, * the generated file will be corrupted. * @param context the context object you receive as return value to a previous call to * encodeMultiple(). Set null for the first image. * @param img the image * @return a context object needed for writing multiple pages for a single image file * @throws IOException In case of an I/O error */ public Object encodeMultiple(Object context, RenderedImage img) throws IOException { // Get the encoding parameters. TIFFEncodeParam encodeParam = (TIFFEncodeParam)param; if (encodeParam.getExtraImages() != null) { throw new IllegalStateException(PropertyUtil.getString("TIFFImageEncoder11")); } Context c = (Context)context; if (c == null) { c = new Context(); // Write the file header (8 bytes). writeFileHeader(); } else { //write image c.ifdOffset = encode(c.nextImage, encodeParam, c.ifdOffset, false); } c.nextImage = img; return c; }