当前位置: 首页>>代码示例>>Java>>正文


Java TranscoderInput类代码示例

本文整理汇总了Java中org.apache.batik.transcoder.TranscoderInput的典型用法代码示例。如果您正苦于以下问题:Java TranscoderInput类的具体用法?Java TranscoderInput怎么用?Java TranscoderInput使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TranscoderInput类属于org.apache.batik.transcoder包,在下文中一共展示了TranscoderInput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createImage

import org.apache.batik.transcoder.TranscoderInput; //导入依赖的package包/类
private byte[] createImage(ImageTranscoder t) throws Exception {
    //*** get the SVG document ***
    SVGDocument doc = this.getSvgDoc();
    org.w3c.dom.Element root = doc.getDocumentElement();
    this.getRoot(root);
    
    //*** set the transcoder input and output ***
    TranscoderInput input = new TranscoderInput(doc);
    ByteArrayOutputStream ostream = new ByteArrayOutputStream();
    TranscoderOutput output = new TranscoderOutput(ostream);

    //*** perform the transcoding ***
    t.transcode(input, output);
    ostream.flush();
    ostream.close();
    return ostream.toByteArray();
}
 
开发者ID:glycoinfo,项目名称:eurocarbdb,代码行数:18,代码来源:SvgFactory.java

示例2: convertSvgToPng

import org.apache.batik.transcoder.TranscoderInput; //导入依赖的package包/类
/**
 * Method for transforming SVG picture to PNG picture
 *
 * @param svgStream input stream of source SVG file
 * @param pngStream output stream of target PNG file
 * @param width     width of the target PNG file
 * @param height    height of the target PNG file
 */
public void convertSvgToPng(InputStream svgStream, OutputStream pngStream, Float width, Float height) {
    notNull(svgStream, IllegalArgumentException::new);
    notNull(pngStream, IllegalArgumentException::new);
    notNull(width, IllegalArgumentException::new);
    notNull(height, IllegalArgumentException::new);
    if (width <= 0 || height <= 0) {
        throw new IllegalArgumentException("Width and height muset be bigger than zero");
    }

    try {
        TranscoderInput input = new TranscoderInput(svgStream);
        TranscoderOutput output = new TranscoderOutput(pngStream);

        PNGTranscoder converter = new PNGTranscoder();
        converter.addTranscodingHint(PNGTranscoder.KEY_WIDTH, width);
        converter.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, height);

        converter.transcode(input, output);

    } catch (TranscoderException ex) {
        throw new SvgConverterException("Exception during transforming SVG to PNG", ex);
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:32,代码来源:SvgConverter.java

示例3: streamOut

import org.apache.batik.transcoder.TranscoderInput; //导入依赖的package包/类
public void streamOut(OutputStream out) {

    // Stream out SVG to the standard output using UTF-8 encoding.
    try {
      TranscoderInput input = new TranscoderInput(svg);
      TranscoderOutput output = new TranscoderOutput(new BufferedWriter(new OutputStreamWriter(out, "UTF-8")));
      Transcoder t = new SVGTranscoder();
      t.transcode(input, output);
    }
    catch (TranscoderException e) {
      e.printStackTrace();
    }
    catch (UnsupportedEncodingException uee) {
      uee.printStackTrace();
    }
  }
 
开发者ID:etomica,项目名称:etomica,代码行数:17,代码来源:GraphMap.java

示例4: transcodeToSVG

import org.apache.batik.transcoder.TranscoderInput; //导入依赖的package包/类
public static byte[] transcodeToSVG(Document doc) {
  try {
    // Determine output type:
    SVGTranscoder t = new SVGTranscoder();

    // Set transcoder input/output
    TranscoderInput input = new TranscoderInput(doc);
    ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
    OutputStreamWriter ostream = new OutputStreamWriter(bytestream);
    TranscoderOutput output = new TranscoderOutput(ostream);

    // Perform transcoding
    t.transcode(input, output);
    ostream.flush();
    ostream.close();

    return bytestream.toByteArray();

  } catch (IOException | TranscoderException e) {
    e.printStackTrace();
  }
  return null;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:24,代码来源:Main.java

示例5: saveImage

import org.apache.batik.transcoder.TranscoderInput; //导入依赖的package包/类
private void saveImage(String svgData) throws Exception{
	PNGTranscoder coder=new PNGTranscoder();
	svgData="<?xml version=\"1.0\" encoding=\"utf-8\"?>"+svgData;
	//ByteArrayInputStream fin=new ByteArrayInputStream(svgData.getBytes());
	StringReader reader=new StringReader(svgData);
	TranscoderInput input=new TranscoderInput(reader);
	String tempDir=ContextHolder.getBdfTempFileStorePath()+DIR;
	File f=new File(tempDir);
	if(!f.exists())f.mkdirs();
	FileOutputStream fout=new FileOutputStream(tempDir+"/process.png");
	TranscoderOutput output=new TranscoderOutput(fout);
	try{
		coder.transcode(input, output);			
	}finally{
		reader.close();
		//fin.close();
		fout.close();			
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:20,代码来源:DesignerServiceController.java

示例6: transcode

import org.apache.batik.transcoder.TranscoderInput; //导入依赖的package包/类
/**
 * Transcodes the specified input in the specified output.
 * @param input the input to transcode
 * @param output the ouput where to transcode
 * @exception TranscoderException if an error occured while transcoding
 */
public void transcode(TranscoderInput input, TranscoderOutput output)
    throws TranscoderException {
    Reader r = input.getReader();
    Writer w = output.getWriter();

    if (r == null) {
        Document d = input.getDocument();
        if (d == null) {
            throw new Error("Reader or Document expected");
        }
        StringWriter sw = new StringWriter( 1024 );
        try {
            DOMUtilities.writeDocument(d, sw);
        } catch ( IOException ioEx ) {
            throw new Error("IO:" + ioEx.getMessage() );
        }
        r = new StringReader(sw.toString());
    }
    if (w == null) {
        throw new Error("Writer expected");
    }
    prettyPrint(r, w);
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:30,代码来源:SVGTranscoder.java

示例7: createTranscoderInput

import org.apache.batik.transcoder.TranscoderInput; //导入依赖的package包/类
/**
 * Creates the <code>TranscoderInput</code>.
 */
protected TranscoderInput createTranscoderInput() {
    DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
    String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
    Document doc = impl.createDocument(svgNS, "svg", null);

    Element root = doc.getDocumentElement();

    root.setAttributeNS(null, "width", "400");
    root.setAttributeNS(null, "height", "400");

    Element r = doc.createElementNS(svgNS, "rect");
    r.setAttributeNS(null, "x", "100");
    r.setAttributeNS(null, "y", "50");
    r.setAttributeNS(null, "width", "100");
    r.setAttributeNS(null, "height", "50");
    r.setAttributeNS(null, "style", "fill:red");
    root.appendChild(r);

    return new TranscoderInput(doc);
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:24,代码来源:BackgroundColorTest.java

示例8: runImpl

import org.apache.batik.transcoder.TranscoderInput; //导入依赖的package包/类
/**
 * Runs this test. This method will only throw exceptions if some aspect of
 * the test's internal operation fails.
 */
public TestReport runImpl() throws Exception {
    report = new DefaultTestReport(this);

    try {
        DiffImageTranscoder transcoder =
            new DiffImageTranscoder(getReferenceImageData());

        Map hints = createTranscodingHints();
        if (hints != null) {
            transcoder.setTranscodingHints(hints);
        }

        TranscoderInput input = createTranscoderInput();
        transcoder.transcode(input, null);
    } catch (Exception ex) {
        report.setErrorCode(ERROR_TRANSCODING);
        report.addDescriptionEntry(ERROR_TRANSCODING, toString(ex));
        ex.printStackTrace();
        report.setPassed(false);
    }

    return report;
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:28,代码来源:AbstractImageTranscoderTest.java

示例9: createTranscoderInput

import org.apache.batik.transcoder.TranscoderInput; //导入依赖的package包/类
/**
 * Creates the <code>TranscoderInput</code>.
 */
protected TranscoderInput createTranscoderInput() {
    try {
        URL url = resolveURL(inputURI);
        String parser = XMLResourceDescriptor.getXMLParserClassName();
        DOMImplementation impl = 
            GenericDOMImplementation.getDOMImplementation();
        SAXDocumentFactory f = new SAXDocumentFactory(impl, parser);
        Document doc = f.createDocument(url.toString());
        TranscoderInput input = new TranscoderInput(doc);
        input.setURI(url.toString()); // Needed for external resources
        return input;
    } catch (IOException ex) {
        ex.printStackTrace();
        throw new IllegalArgumentException(inputURI);
    }
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:20,代码来源:GenericDocumentTest.java

示例10: loadSvg

import org.apache.batik.transcoder.TranscoderInput; //导入依赖的package包/类
private static BufferedImage loadSvg(DomApplication da, IResourceDependencyList rdl, String image, IParameterInfo param) throws Exception {
	//-- 1. Get the input as a theme-replaced resource
	String svg = da.internalGetThemeManager().getThemeReplacedString(rdl, image);

	//-- 2. Now generate the thingy using the Batik transcoder:
	BufferedImageTranscoder bit = new BufferedImageTranscoder();
	TranscoderInput in = new TranscoderInput(new StringReader(svg));

	int w = PartUtil.getInt(param, "w", -1);
	int h = PartUtil.getInt(param, "h", -1);

	if(w != -1 && h != -1) {
		bit.addTranscodingHint(SVGAbstractTranscoder.KEY_WIDTH, Float.valueOf(w));
		bit.addTranscodingHint(SVGAbstractTranscoder.KEY_HEIGHT, Float.valueOf(h));
	}
	bit.transcode(in, new TranscoderOutput());
	return bit.getRendered();
}
 
开发者ID:fjalvingh,项目名称:domui,代码行数:19,代码来源:PartUtil.java

示例11: generate

import org.apache.batik.transcoder.TranscoderInput; //导入依赖的package包/类
@Override
public void generate(@Nonnull PartResponse pr, @Nonnull DomApplication da, @Nonnull SvgKey k, @Nonnull IResourceDependencyList rdl) throws Exception {
	//-- 1. Get the input as a theme-replaced resource
	String svg = da.internalGetThemeManager().getThemeReplacedString(rdl, k.getRurl());

	//-- 2. Now generate the thingy using the Batik transcoder:
	PNGTranscoder coder = new PNGTranscoder();
	//		coder.addTranscodingHint(PNGTranscoder., null);
	TranscoderInput in = new TranscoderInput(new StringReader(svg));
	TranscoderOutput out = new TranscoderOutput(pr.getOutputStream());

	if(k.getWidth() != -1 && k.getHeight() != -1) {
		coder.addTranscodingHint(SVGAbstractTranscoder.KEY_WIDTH, Float.valueOf(k.getWidth()));
		coder.addTranscodingHint(SVGAbstractTranscoder.KEY_HEIGHT, Float.valueOf(k.getHeight()));
	}

	coder.transcode(in, out);

	if(!da.inDevelopmentMode()) { // Not gotten from WebContent or not in DEBUG mode? Then we may cache!
		pr.setCacheTime(da.getDefaultExpiryTime());
	}
	pr.setMime("image/png");
}
 
开发者ID:fjalvingh,项目名称:domui,代码行数:24,代码来源:SvgPartFactory.java

示例12: getImage

import org.apache.batik.transcoder.TranscoderInput; //导入依赖的package包/类
public Image getImage(double width, double height) throws IOException {

        PNGTranscoder t = new PNGTranscoder();
        t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, (float) width);
        t.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, (float) height);

        t.addTranscodingHint(PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE, true);

        TranscoderInput input = new TranscoderInput(svgDocument);
        ByteArrayOutputStream ostream = new ByteArrayOutputStream(1000);
        TranscoderOutput output2 = new TranscoderOutput(ostream);
        try {
            // Save the image.
            t.transcode(input, output2);
        } catch (TranscoderException ex) {
            Exceptions.printStackTrace(ex);
        }

        BufferedImage imag = ImageIO.read(new ByteArrayInputStream(ostream.toByteArray()));
        // ImageIO.write(imag, "png", new File(new Date().getTime()+".png"));
        ostream.flush();
        ostream.close();

        return imag;
    }
 
开发者ID:jeddict,项目名称:NBModeler,代码行数:26,代码来源:SvgImage.java

示例13: updateImage

import org.apache.batik.transcoder.TranscoderInput; //导入依赖的package包/类
private void updateImage() {
  if (document == null) {
    return;
  }
  try {
    if (canvasWidth >= 0) {
      addTranscodingHint(SVGAbstractTranscoder.KEY_WIDTH, new Float(canvasWidth));
    } else {
      removeTranscodingHint(SVGAbstractTranscoder.KEY_WIDTH);
    }
    if (canvasHeight >= 0) {
      addTranscodingHint(SVGAbstractTranscoder.KEY_HEIGHT, new Float(canvasHeight));
    } else {
      removeTranscodingHint(SVGAbstractTranscoder.KEY_HEIGHT);
    }
    if (canvasAOI != null) {
      addTranscodingHint(SVGAbstractTranscoder.KEY_AOI, canvasAOI);
    } else {
      removeTranscodingHint(SVGAbstractTranscoder.KEY_AOI);
    }
    transcode(new TranscoderInput(document), new TranscoderOutput());
  } catch (TranscoderException e) {
    TriqEditorPlugin.logError("Error transcoding SVG image", e);
  }
}
 
开发者ID:eclipse,项目名称:triquetrum,代码行数:26,代码来源:SimpleImageTranscoder.java

示例14: convertSvgToPng

import org.apache.batik.transcoder.TranscoderInput; //导入依赖的package包/类
private static void convertSvgToPng(String svg, String png, int origSize, int dstSize, Color bg) throws Exception {
    String svg_URI_input = Paths.get(svg).toUri().toURL().toString();
    TranscoderInput input_svg_image = new TranscoderInput(svg_URI_input);
    OutputStream png_ostream = new FileOutputStream(png);
    TranscoderOutput output_png_image = new TranscoderOutput(png_ostream);
    PNGTranscoder my_converter = new PNGTranscoder();
    my_converter.addTranscodingHint( PNGTranscoder.KEY_WIDTH, new Float( dstSize ) );
    my_converter.addTranscodingHint( PNGTranscoder.KEY_HEIGHT, new Float( dstSize ) );
    my_converter.addTranscodingHint( PNGTranscoder.KEY_AOI, new Rectangle( 0, 0, origSize, origSize) );
    if (bg != null) {
        my_converter.addTranscodingHint( PNGTranscoder.KEY_BACKGROUND_COLOR, bg);
    }
    my_converter.transcode(input_svg_image, output_png_image);
    png_ostream.flush();
    png_ostream.close();
}
 
开发者ID:jruesga,项目名称:cm-cloud-generator,代码行数:17,代码来源:CloudGenerator.java

示例15: updateImage

import org.apache.batik.transcoder.TranscoderInput; //导入依赖的package包/类
private void updateImage() {
	if (document == null) {
		return;
	}
	try {
		if (canvasWidth >= 0) {
			addTranscodingHint(ImageTranscoder.KEY_WIDTH, new Float(canvasWidth));
		} else {
			removeTranscodingHint(ImageTranscoder.KEY_WIDTH);
		}
		if (canvasHeight >= 0) {
			addTranscodingHint(ImageTranscoder.KEY_HEIGHT, new Float(canvasHeight));
		} else {
			removeTranscodingHint(ImageTranscoder.KEY_HEIGHT);
		}
		if (canvasAOI != null) {
			addTranscodingHint(ImageTranscoder.KEY_AOI, canvasAOI);
		} else {
			removeTranscodingHint(ImageTranscoder.KEY_AOI);
		}
		transcode(new TranscoderInput(document), new TranscoderOutput());
	} catch (TranscoderException e) {
		JaspersoftStudioPlugin.getInstance().logError("Error transcoding SVG image", e);
	}
}
 
开发者ID:OpenSoftwareSolutions,项目名称:PDFReporter-Studio,代码行数:26,代码来源:SimpleImageTranscoder.java


注:本文中的org.apache.batik.transcoder.TranscoderInput类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。