t.transcode(input, null); } catch (Exception e) { throw new IOException("Couldn't convert svg file: " + svgFile + " , reason: " + e.getMessage());
protected void transcode(Document document, String uri, TranscoderOutput output) throws TranscoderException { super.transcode(document, uri, output); this.doc = document; }
public void transcode ( Document inputDoc ) throws Exception { super.transcode(inputDoc,null,null); }
private static ByteArrayOutputStream saveAsBytes(ImageTranscoder t, Document doc) throws Exception { TranscoderInput input = new TranscoderInput(doc); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(outputStream); t.transcode(input, output); outputStream.flush(); return outputStream; }
/** * Helper method: creates a valid reference image */ public static URL createValidReferenceImage(String svgContent) throws Exception{ TranscoderInput validSrc = new TranscoderInput(new StringReader(svgContent)); File tmpFile = File.createTempFile(SVGRenderingAccuracyTest.TEMP_FILE_PREFIX, SVGRenderingAccuracyTest.TEMP_FILE_SUFFIX); TranscoderOutput validDst = new TranscoderOutput(new FileOutputStream(tmpFile)); ImageTranscoder transcoder = new PNGTranscoder(); transcoder.transcode(validSrc, validDst); tmpFile.deleteOnExit(); return tmpFile.toURI().toURL(); }
private static byte[] getRasterImageByteArray(final Document document, final int width, final ImageFormat imageFormat) { // Create a image transcoder final ImageTranscoder t; if (imageFormat == ImageFormat.JPEG) { t = new JPEGTranscoder(); t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(.8)); t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new Float(width)); // } else if (imageFormat == ImageFormat.TIFF) { // t = new TIFFTranscoder(); // t.addTranscodingHint(TIFFTranscoder.KEY_WIDTH, new Float(width)); } else { t = new PNGTranscoder(); t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(width)); } // Set the transcoding hints. TranscoderInput input = new TranscoderInput(document); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final TranscoderOutput output = new TranscoderOutput(baos); // Save the image. try { t.transcode(input, output); } catch (TranscoderException ex) { log.error("Exception encountered " + ex, ex); } return baos.toByteArray(); }
TranscoderInput src = new TranscoderInput(svgURL.toString()); TranscoderOutput dst = new TranscoderOutput(fos); transcoder.transcode(src, dst); return null; }catch(TranscoderException e){
t.transcode(input, output);
t.transcode(input, null);
public BufferedImage getRasterizedSVG() { if (rasterizedSVG != null) { return rasterizedSVG; } try { rasterizedSVG = new BufferedImage( (int) Math.round(getPageSize().getWidth()), (int) Math.round(getPageSize().getHeight()), BufferedImage.TYPE_INT_ARGB); ImageTranscoder transcoder = new ImageTranscoder() { @Override public BufferedImage createImage(int width, int height) { return rasterizedSVG; } @Override public void writeImage(BufferedImage bufferedImage, TranscoderOutput transcoderOutput) throws TranscoderException { } }; transcoder.transcode(new TranscoderInput(getSVG()), null); } catch (TranscoderException e) { e.printStackTrace(); } return rasterizedSVG; } }