@PutMapping(value = "/{modelId}") @ResponseStatus(value = HttpStatus.OK) @Authorize(action = Permission.ACTION_UPDATE) public void saveModel(@PathVariable String modelId, @RequestParam Map<String, String> values) throws TranscoderException, IOException { Model model = repositoryService.getModel(modelId); JSONObject modelJson = JSON.parseObject(model.getMetaInfo()); modelJson.put(MODEL_NAME, values.get("name")); modelJson.put(MODEL_DESCRIPTION, values.get("description")); model.setMetaInfo(modelJson.toString()); model.setName(values.get("name")); repositoryService.saveModel(model); repositoryService.addModelEditorSource(model.getId(), values.get("json_xml").getBytes("utf-8")); InputStream svgStream = new ByteArrayInputStream(values.get("svg_xml").getBytes("utf-8")); TranscoderInput input = new TranscoderInput(svgStream); PNGTranscoder transcoder = new PNGTranscoder(); // Setup output ByteArrayOutputStream outStream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(outStream); // Do the transformation transcoder.transcode(input, output); final byte[] result = outStream.toByteArray(); repositoryService.addModelEditorSourceExtra(model.getId(), result); outStream.close(); }
transcoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, w); transcoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, h); transcoder.transcode(new TranscoderInput(in), new TranscoderOutput(out));
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import org.apache.batik.transcoder.Transcoder; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; import org.apache.fop.svg.PDFTranscoder; public class Test { public static void main(String[] argv) throws TranscoderException, FileNotFoundException { Transcoder transcoder = new PDFTranscoder(); TranscoderInput transcoderInput = new TranscoderInput(new FileInputStream(new File("/tmp/test.svg"))); TranscoderOutput transcoderOutput = new TranscoderOutput(new FileOutputStream(new File("/tmp/test.pdf"))); transcoder.transcode(transcoderInput, transcoderOutput); } }
@Override public void setInput(Object pInput, boolean seekForwardOnly, boolean ignoreMetadata) { super.setInput(pInput, seekForwardOnly, ignoreMetadata); if (imageInput != null) { TranscoderInput input = new TranscoderInput(IIOUtil.createStreamAdapter(imageInput)); rasterizer.setInput(input); } }
private synchronized void init() throws IOException { // Need the extra test, to avoid throwing an IOException from the Transcoder if (imageInput == null) { throw new IllegalStateException("input == null"); } if (reader == null) { WMFTranscoder transcoder = new WMFTranscoder(); ByteArrayOutputStream output = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(output, "UTF8"); try { TranscoderInput in = new TranscoderInput(IIOUtil.createStreamAdapter(imageInput)); TranscoderOutput out = new TranscoderOutput(writer); // TODO: Transcodinghints? transcoder.transcode(in, out); } catch (TranscoderException e) { throw new IIOException(e.getMessage(), e); } reader = new SVGImageReader(getOriginatingProvider()); reader.setInput(ImageIO.createImageInputStream(new ByteArrayInputStream(output.toByteArray()))); } }
TranscoderInput input = new TranscoderInput(new FileInputStream(svgFile));
TranscoderInput input = new TranscoderInput(svgStream);
TranscoderInput input = new TranscoderInput(new FileInputStream(svgFile)); ImageTranscoder t = new ImageTranscoder() {
/** * Constructs a new SVGRasterizer converter. * * @param istream the input stream that represents the SVG document to * rasterize */ public SVGRasterizer(InputStream istream) { this.input = new TranscoderInput(istream); }
/** * Constructs a new SVGRasterizer. * * @param uri the uri of the document to rasterize */ public SVGRasterizer(String uri) { this.input = new TranscoderInput(uri); }
/** * Constructs a new SVGRasterizer converter. * * @param reader the reader that represents the SVG document to rasterize */ public SVGRasterizer(Reader reader) { this.input = new TranscoderInput(reader); }
/** * Constructs a new SVGRasterizer. * * @param url the URL of the document to rasterize */ public SVGRasterizer(URL url) { this.input = new TranscoderInput(url.toString()); }
public static BufferedImage loadImage(File svgFile, float width, float height) { BufferedImageTranscoder imageTranscoder = new BufferedImageTranscoder(); imageTranscoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, width); imageTranscoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, height); TranscoderInput input = new TranscoderInput(svgFile); imageTranscoder.transcode(input, null); return imageTranscoder.getBufferedImage(); }
/** * Create a new SVGIcon object. * * @param uri The URI to read the SVG document from. */ public SvgIcon(URL url, int width, int height) { try { generateBufferedImage(new TranscoderInput(url.toString()), width, height); } catch (Exception e) { e.printStackTrace(); } }
MyTranscoder imageTranscoder = new MyTranscoder(); imageTranscoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, (float) width); imageTranscoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, (float) height); TranscoderInput input = new TranscoderInput(new FileReader(file)); imageTranscoder.transcode(input, null); BufferedImage bimage = imageTranscoder.getImage(); WritableImage wimage = SwingFXUtils.toFXImage(bimage, null); ImageView imageView = new ImageView(wimage); <panel-vbox-whatever>.getChildren().clear(); <panel-vbox-whatever>.getChildren().add(imageView);
private void rasterizeToFile(String content, File out, int width, int height) throws IOException { if (out.exists()) { this.logger.debug("Reusing existing temporary raster image: {}", out.getAbsolutePath()); return; } try (OutputStream fout = new FileOutputStream(out)) { this.logger.debug("Rasterizing to temp file: {}", out.getAbsolutePath()); TranscoderInput input = new TranscoderInput(new StringReader(content)); TranscoderOutput output = new TranscoderOutput(fout); rasterize(input, output, width, height); } }
private void rasterizeToFile(String content, File out, int width, int height) throws IOException { if (out.exists()) { this.logger.debug("Reusing existing temporary raster image: {}", out.getAbsolutePath()); return; } try (OutputStream fout = new FileOutputStream(out)) { this.logger.debug("Rasterizing to temp file: {}", out.getAbsolutePath()); TranscoderInput input = new TranscoderInput(new StringReader(content)); TranscoderOutput output = new TranscoderOutput(fout); rasterize(input, output, width, height); } }
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; }
@Override public void setInput(Object pInput, boolean seekForwardOnly, boolean ignoreMetadata) { super.setInput(pInput, seekForwardOnly, ignoreMetadata); if (imageInput != null) { TranscoderInput input = new TranscoderInput(IIOUtil.createStreamAdapter(imageInput)); rasterizer.setInput(input); } }
private BufferedImage getTranscodedImage(Document document, float width, float height) throws TranscoderException { BufferedImageTranscoder trans = new BufferedImageTranscoder(BufferedImage.TYPE_INT_ARGB); trans.addTranscodingHint(KEY_WIDTH, width); trans.addTranscodingHint(KEY_HEIGHT, height); trans.transcode(new TranscoderInput(document), null); return trans.getBufferedImage(); }