MyTranscoder transcoder = new MyTransCoder(); TranscodingHints hints = new TranscodingHints(); hints.put(ImageTranscoder.KEY_WIDTH, width); hints.put(ImageTranscoder.KEY_HEIGHT, height); transcoder.setTranscodingHints(hints); transcoder.transcode(new TranscoderInput(url), null); BufferedImage image = transcoder.getImage();
transcoderHints.put(ImageTranscoder.KEY_XML_PARSER_VALIDATING, Boolean.FALSE); transcoderHints.put(ImageTranscoder.KEY_DOM_IMPLEMENTATION, SVGDOMImplementation.getDOMImplementation()); transcoderHints.put(ImageTranscoder.KEY_DOCUMENT_ELEMENT_NAMESPACE_URI, SVGConstants.SVG_NAMESPACE_URI); transcoderHints.put(ImageTranscoder.KEY_DOCUMENT_ELEMENT, "svg"); transcoderHints.put(ImageTranscoder.KEY_USER_STYLESHEET_URI, cssFile.toURI().toString());
hints.put(ImageTranscoder.KEY_WIDTH, (float) size.getWidth()); hints.put(ImageTranscoder.KEY_HEIGHT, (float) size.getHeight()); hints.put(ImageTranscoder.KEY_AOI, region); hints.put(ImageTranscoder.KEY_WIDTH, (float) region.getWidth()); hints.put(ImageTranscoder.KEY_HEIGHT, (float) region.getHeight()); double yScale = size.getHeight() / origSize.getHeight(); hints.put(ImageTranscoder.KEY_WIDTH, (float) (region.getWidth() * xScale)); hints.put(ImageTranscoder.KEY_HEIGHT, (float) (region.getHeight() * yScale)); hints.put(ImageTranscoder.KEY_AOI, new Rectangle(origSize)); hints.put(ImageTranscoder.KEY_BACKGROUND_COLOR, bg);
transcoderHints.put(ImageTranscoder.KEY_WIDTH, (float) resizeToWidth); //your image width transcoderHints.put(ImageTranscoder.KEY_HEIGHT, (float) resizeToHeight); //your image height transcoderHints.put(ImageTranscoder.KEY_XML_PARSER_VALIDATING, Boolean.FALSE); transcoderHints.put(ImageTranscoder.KEY_DOM_IMPLEMENTATION, SVGDOMImplementation.getDOMImplementation()); transcoderHints.put(ImageTranscoder.KEY_DOCUMENT_ELEMENT_NAMESPACE_URI, SVGConstants.SVG_NAMESPACE_URI); transcoderHints.put(ImageTranscoder.KEY_DOCUMENT_ELEMENT, "svg"); transcoderHints.put(ImageTranscoder.KEY_USER_STYLESHEET_URI, cssFile.toURI().toString());
/** * Sets the uri of the user stylesheet. The user stylesheet can be used to * override styles. * * @param uri the uri of the user stylesheet */ public void setUserStyleSheetURI(String uri) { hints.put(ImageTranscoder.KEY_USER_STYLESHEET_URI, uri); }
/** * Sets the alternate stylesheet to use. For further details, you can have * a look at the <a href="http://www.w3.org/TR/xml-stylesheet/">Associating * Style Sheets with XML documents</a>. * * @param alternateStylesheet the alternate stylesheet to use if possible */ public void setAlternateStylesheet(String alternateStylesheet) { hints.put(ImageTranscoder.KEY_ALTERNATE_STYLESHEET, alternateStylesheet); }
/** * Constructor. */ public ThumbnailTranscoder() { super(); hints.put(KEY_FORCE_TRANSPARENT_WHITE, Boolean.FALSE); }
/** * Constructs a new transcoder that prints images. */ public PrintTranscoder() { super(); hints.put(KEY_MEDIA, VALUE_MEDIA_PRINT); }
/** * Constructs a new transcoder that produces tiff images. */ public TIFFTranscoder() { hints.put(KEY_FORCE_TRANSPARENT_WHITE, Boolean.FALSE); }
/** * Constructs a new transcoder that produces tiff images. */ public TIFFTranscoder() { hints.put(KEY_FORCE_TRANSPARENT_WHITE, Boolean.FALSE); }
/** * Sets the media to rasterize. The medium should be separated by * comma. e.g. "screen", "print" or "screen, print" * * @param media the media to use */ public void setMedia(String media) { hints.put(ImageTranscoder.KEY_MEDIA, media); }
/** * Constructs a new transcoder that prints images. */ public PrintTranscoder() { super(); hints.put(KEY_MEDIA, VALUE_MEDIA_PRINT); }
/** * Constructor. */ public ThumbnailTranscoder() { super(); hints.put(KEY_FORCE_TRANSPARENT_WHITE, Boolean.FALSE); }
/** * Sets the Paint to use for the background of the image. * * @param p the paint to use for the background */ public void setBackgroundColor(Paint p) { hints.put(ImageTranscoder.KEY_BACKGROUND_COLOR, p); }
/** * Sets the unit conversion factor to the specified value. This method * lets you choose how units such as 'em' are converted. e.g. 0.26458 is * 96dpi (the default) or 0.3528 is 72dpi. * * @param px2mm the pixel to millimeter conversion factor. */ public void setPixelToMMFactor(float px2mm) { hints.put(ImageTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER, new Float(px2mm)); }
/** * Sets the quality of the image to rasterize when rasterizing to a JPEG. * @param quality the percentage quality */ public void setQuality(float quality) { hints.put(JPEGTranscoder.KEY_QUALITY, new Float(quality)); }
/** * Sets the height of the image to rasterize. * * @param height the image height */ public void setImageHeight(float height) { hints.put(ImageTranscoder.KEY_HEIGHT, new Float(height)); }
String uri = "path_to_svg/some.svg"; MyTranscoder transcoder = new MyTranscoder(); TranscodingHints hints = new TranscodingHints(); hints.put(ImageTranscoder.KEY_WIDTH, 20f); //your image width hints.put(ImageTranscoder.KEY_HEIGHT, 20f); //your image height hints.put(ImageTranscoder.KEY_DOM_IMPLEMENTATION, SVGDOMImplementation.getDOMImplementation()); hints.put(ImageTranscoder.KEY_DOCUMENT_ELEMENT_NAMESPACE_URI, SVGConstants.SVG_NAMESPACE_URI); hints.put(ImageTranscoder.KEY_DOCUMENT_ELEMENT, SVGConstants.SVG_SVG_TAG); hints.put(ImageTranscoder.KEY_XML_PARSER_VALIDATING, false); transcoder.setTranscodingHints(hints); TranscoderInput input = new TranscoderInput(url.toExternalForm()); transcoder.transcode(input, null); BufferedImage bufferedImage = transcoder.getImage();
private static TranscodingHints createTranscodingHints(int width, int height) { TranscodingHints hints = new TranscodingHints(); hints.put(ImageTranscoder.KEY_DOM_IMPLEMENTATION, SVGDOMImplementation.getDOMImplementation()); hints.put(ImageTranscoder.KEY_DOCUMENT_ELEMENT_NAMESPACE_URI, SVGConstants.SVG_NAMESPACE_URI); hints.put(ImageTranscoder.KEY_DOCUMENT_ELEMENT, "svg"); hints.put(ImageTranscoder.KEY_WIDTH, (float)width); hints.put(ImageTranscoder.KEY_HEIGHT, (float)height); return hints; }