本文整理汇总了Java中org.apache.batik.transcoder.Transcoder.transcode方法的典型用法代码示例。如果您正苦于以下问题:Java Transcoder.transcode方法的具体用法?Java Transcoder.transcode怎么用?Java Transcoder.transcode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.batik.transcoder.Transcoder
的用法示例。
在下文中一共展示了Transcoder.transcode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: streamOut
import org.apache.batik.transcoder.Transcoder; //导入方法依赖的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();
}
}
示例2: convert
import org.apache.batik.transcoder.Transcoder; //导入方法依赖的package包/类
private void convert(String svgFileName, String pngFileName)
{
Transcoder transcoder = new PNGTranscoder();
Map<TranscodingHints.Key, Float> hints =
new HashMap<TranscodingHints.Key, Float>();
hints.put(ImageTranscoder.KEY_MAX_HEIGHT, new Float(750));
hints.put(ImageTranscoder.KEY_MAX_WIDTH, new Float(750));
transcoder.setTranscodingHints(hints);
try {
TranscoderInput input =
new TranscoderInput(new File(svgFileName).toURI().toString());
TranscoderOutput output =
new TranscoderOutput(new FileOutputStream(pngFileName));
transcoder.transcode(input, output);
} catch (Exception e) {
throw new RuntimeException("Transcoding failed.", e);
}
}
示例3: convert
import org.apache.batik.transcoder.Transcoder; //导入方法依赖的package包/类
private void convert(String svgFileName, String pngFileName)
{
Transcoder transcoder = new PNGTranscoder();
Map<TranscodingHints.Key, Float> hints =
new HashMap<TranscodingHints.Key, Float>();
hints.put(ImageTranscoder.KEY_MAX_HEIGHT, new Float(200));
hints.put(ImageTranscoder.KEY_MAX_WIDTH, new Float(750));
transcoder.setTranscodingHints(hints);
try {
TranscoderInput input =
new TranscoderInput(new File(svgFileName).toURI().toString());
TranscoderOutput output =
new TranscoderOutput(new FileOutputStream(pngFileName));
transcoder.transcode(input, output);
} catch (Exception e) {
throw new RuntimeException("Transcoding failed.", e);
}
}
示例4: export
import org.apache.batik.transcoder.Transcoder; //导入方法依赖的package包/类
@Override
public void export(Model model, OutputStream out) throws IOException, SerialisationException {
InputStream svg = SvgExportUtils.stream(model);
Transcoder transcoder = new EPSTranscoder();
TranscoderInput transcoderInput = new TranscoderInput(svg);
TranscoderOutput transcoderOutput = new TranscoderOutput(out);
try {
transcoder.transcode(transcoderInput, transcoderOutput);
} catch (TranscoderException e) {
throw new SerialisationException(e);
}
}
示例5: export
import org.apache.batik.transcoder.Transcoder; //导入方法依赖的package包/类
@Override
public void export(Model model, OutputStream out) throws IOException, SerialisationException {
InputStream svg = SvgExportUtils.stream(model);
Transcoder transcoder = new PSTranscoder();
TranscoderInput transcoderInput = new TranscoderInput(svg);
TranscoderOutput transcoderOutput = new TranscoderOutput(out);
try {
transcoder.transcode(transcoderInput, transcoderOutput);
} catch (TranscoderException e) {
throw new SerialisationException(e);
}
}
示例6: export
import org.apache.batik.transcoder.Transcoder; //导入方法依赖的package包/类
@Override
public void export(Model model, OutputStream out) throws IOException, SerialisationException {
InputStream svg = SvgExportUtils.stream(model);
Transcoder transcoder = new PDFTranscoder();
TranscoderInput transcoderInput = new TranscoderInput(svg);
TranscoderOutput transcoderOutput = new TranscoderOutput(out);
try {
transcoder.transcode(transcoderInput, transcoderOutput);
} catch (TranscoderException e) {
throw new SerialisationException(e);
}
}
示例7: export
import org.apache.batik.transcoder.Transcoder; //导入方法依赖的package包/类
@Override
public void export(Model model, OutputStream out) throws IOException, SerialisationException {
InputStream svg = SvgExportUtils.stream(model);
Transcoder transcoder = new PNGTranscoder();
TranscoderInput transcoderInput = new TranscoderInput(svg);
TranscoderOutput transcoderOutput = new TranscoderOutput(out);
try {
transcoder.transcode(transcoderInput, transcoderOutput);
} catch (TranscoderException e) {
throw new SerialisationException(e);
}
}
示例8: transcode
import org.apache.batik.transcoder.Transcoder; //导入方法依赖的package包/类
/**
* Transcode a document into a file using the given transcoder.
*
* @param file Output file
* @param transcoder Transcoder to use
* @throws IOException On write errors
* @throws TranscoderException On input/parsing errors
*/
protected void transcode(File file, Transcoder transcoder) throws IOException, TranscoderException {
// Disable validation, performance is more important here (thumbnails!)
transcoder.addTranscodingHint(XMLAbstractTranscoder.KEY_XML_PARSER_VALIDATING, Boolean.FALSE);
SVGDocument doc = cloneDocument();
TranscoderInput input = new TranscoderInput(doc);
OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
TranscoderOutput output = new TranscoderOutput(out);
transcoder.transcode(input, output);
out.flush();
out.close();
}
示例9: transcodeDom
import org.apache.batik.transcoder.Transcoder; //导入方法依赖的package包/类
private void transcodeDom(Transcoder transcoder) throws IOException, TranscoderException {
TranscoderInput transcoderInput = new TranscoderInput(savePanel.getGraphPanel().doc);
OutputStream outputStream = new java.io.FileOutputStream(outputFile);
outputStream = new java.io.BufferedOutputStream(outputStream);
try {
TranscoderOutput transcoderOutput = new TranscoderOutput(outputStream);
// todo: resolve the issue here when transcoding to jpg
transcoder.transcode(transcoderInput, transcoderOutput);
} finally {
outputStream.close();
}
}
示例10: convertSVG2PDF
import org.apache.batik.transcoder.Transcoder; //导入方法依赖的package包/类
/**
* Converts an FO file to a PDF file using FOP
* @param svg the SVG file
* @param pdf the target PDF file
* @throws IOException In case of an I/O problem
* @throws TranscoderException In case of a transcoding problem
*/
public void convertSVG2PDF(File svg, File pdf) throws IOException, TranscoderException {
//Create transcoder
Transcoder transcoder = new PDFTranscoder();
//Transcoder transcoder = new org.apache.fop.render.ps.PSTranscoder();
//Setup input
InputStream in = new java.io.FileInputStream(svg);
try {
TranscoderInput input = new TranscoderInput(in);
//Setup output
OutputStream out = new java.io.FileOutputStream(pdf);
out = new java.io.BufferedOutputStream(out);
try {
TranscoderOutput output = new TranscoderOutput(out);
//Do the transformation
transcoder.transcode(input, output);
} finally {
out.close();
}
} finally {
in.close();
}
}
示例11: testGenericPDFTranscoder
import org.apache.batik.transcoder.Transcoder; //导入方法依赖的package包/类
/**
* Runs the PDF transcoder as if it were called by Batik's rasterizer.
* Without special configuration stuff.
* @throws Exception if a problem occurs
*/
@Test
public void testGenericPDFTranscoder() throws Exception {
//Create transcoder
Transcoder transcoder = createTranscoder();
//Setup input
File svgFile = new File(getBaseDir(), "test/resources/fop/svg/text.svg");
InputStream in = new java.io.FileInputStream(svgFile);
try {
TranscoderInput input = new TranscoderInput(in);
//Setup output
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
TranscoderOutput output = new TranscoderOutput(out);
//Do the transformation
transcoder.transcode(input, output);
} finally {
out.close();
}
assertTrue("Some output expected", out.size() > 0);
} finally {
in.close();
}
}
示例12: exportPlot
import org.apache.batik.transcoder.Transcoder; //导入方法依赖的package包/类
/**
* Exports the selected file to the wanted format.
*
* @param exportFile
* @param imageType
* @param svgGenerator
* @throws IOException
* @throws TranscoderException
*/
private static void exportPlot(File exportFile, ImageType imageType, SVGGraphics2D svgGenerator)
throws IOException, TranscoderException {
// write the svg file
File svgFile = exportFile;
if (imageType != ImageType.SVG) {
svgFile = new File(exportFile.getAbsolutePath() + ".temp");
}
OutputStream outputStream = new FileOutputStream(svgFile);
BufferedOutputStream bos = new BufferedOutputStream(outputStream);
Writer out = new OutputStreamWriter(bos, "UTF-8");
svgGenerator.stream(out, true /* use css */);
outputStream.flush();
outputStream.close();
bos.close();
// if selected image format is not svg, convert the image
if (imageType != ImageType.SVG) {
// set up the svg input
String svgURI = svgFile.toURI().toString();
TranscoderInput svgInputFile = new TranscoderInput(svgURI);
OutputStream outstream = new FileOutputStream(exportFile);
bos = new BufferedOutputStream(outstream);
TranscoderOutput output = new TranscoderOutput(bos);
if (imageType == ImageType.PDF) {
// write as pdf
Transcoder pdfTranscoder = new PDFTranscoder();
pdfTranscoder.addTranscodingHint(PDFTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER, new Float(0.084666f));
pdfTranscoder.transcode(svgInputFile, output);
} else if (imageType == ImageType.JPEG) {
// write as jpeg
Transcoder jpegTranscoder = new JPEGTranscoder();
jpegTranscoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1.0));
jpegTranscoder.transcode(svgInputFile, output);
} else if (imageType == ImageType.TIFF) {
// write as tiff
Transcoder tiffTranscoder = new TIFFTranscoder();
tiffTranscoder.addTranscodingHint(TIFFTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER, new Float(0.084666f));
tiffTranscoder.addTranscodingHint(TIFFTranscoder.KEY_FORCE_TRANSPARENT_WHITE, true);
tiffTranscoder.transcode(svgInputFile, output);
} else if (imageType == ImageType.PNG) {
// write as png
Transcoder pngTranscoder = new PNGTranscoder();
pngTranscoder.addTranscodingHint(PNGTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER, new Float(0.084666f));
pngTranscoder.transcode(svgInputFile, output);
}
//close the stream
outstream.flush();
outstream.close();
bos.close();
// delete the svg file given that the selected format is not svg
if (svgFile.exists()) {
svgFile.delete();
}
}
}
示例13: exportPlot
import org.apache.batik.transcoder.Transcoder; //导入方法依赖的package包/类
/**
* Exports the selected file to the wanted format.
*
* @param exportFile
* @param imageType
* @param svgGenerator
* @throws IOException
* @throws TranscoderException
*/
private static void exportPlot(File exportFile, ImageType imageType, SVGGraphics2D svgGenerator)
throws IOException, TranscoderException {
// write the svg file
File svgFile = exportFile;
if (imageType != ImageType.SVG) {
svgFile = new File(exportFile.getAbsolutePath() + ".temp");
}
OutputStream outputStream = new FileOutputStream(svgFile);
Writer out = new OutputStreamWriter(outputStream, "UTF-8");
svgGenerator.stream(out, true /* use css */);
outputStream.flush();
outputStream.close();
// if selected image format is not svg, convert the image
if (imageType != ImageType.SVG) {
// set up the svg input
String svgURI = svgFile.toURI().toString();
TranscoderInput svgInputFile = new TranscoderInput(svgURI);
OutputStream outstream = new FileOutputStream(exportFile);
TranscoderOutput output = new TranscoderOutput(outstream);
if (imageType == ImageType.PDF) {
// write as pdf
Transcoder pdfTranscoder = new PDFTranscoder();
pdfTranscoder.addTranscodingHint(PDFTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER, new Float(0.084666f));
pdfTranscoder.transcode(svgInputFile, output);
} else if (imageType == ImageType.JPEG) {
// write as jpeg
Transcoder jpegTranscoder = new JPEGTranscoder();
jpegTranscoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1.0));
jpegTranscoder.transcode(svgInputFile, output);
} else if (imageType == ImageType.TIFF) {
// write as tiff
Transcoder tiffTranscoder = new TIFFTranscoder();
tiffTranscoder.addTranscodingHint(TIFFTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER, new Float(0.084666f));
tiffTranscoder.addTranscodingHint(TIFFTranscoder.KEY_FORCE_TRANSPARENT_WHITE, true);
tiffTranscoder.transcode(svgInputFile, output);
} else if (imageType == ImageType.PNG) {
// write as png
Transcoder pngTranscoder = new PNGTranscoder();
pngTranscoder.addTranscodingHint(PNGTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER, new Float(0.084666f));
pngTranscoder.transcode(svgInputFile, output);
}
//close the stream
outstream.flush();
outstream.close();
// delete the svg file given that the selected format is not svg
if (svgFile.exists()) {
svgFile.delete();
}
}
}
示例14: main
import org.apache.batik.transcoder.Transcoder; //导入方法依赖的package包/类
/**
* @param args
* @throws IOException
* @throws TranscoderException
*/
public static void main(String[] args) throws IOException, TranscoderException {
InputStream resourceAsStream = SVGMainTests.class.getResourceAsStream("/br/com/dlp/jazzav/modeloanuncio/teste.svg");
InputStream fis = resourceAsStream;
FileOutputStream fos = new FileOutputStream("teste.png");
Transcoder transcoder = new PNGTranscoder();
Map hintMap = new HashMap();
hintMap.put(PNGTranscoder.KEY_BACKGROUND_COLOR,Color.BLACK);
transcoder.setTranscodingHints(hintMap);
TranscoderInput in = new TranscoderInput(fis);
TranscoderOutput out = new TranscoderOutput(fos);
transcoder.transcode(in, out);
fos.flush();
fos.close();
/*
AffineTransform xform = new AffineTransform();
xform.rotate(Math.toRadians(30));
AffineTransformOp op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
*/
}
示例15: write
import org.apache.batik.transcoder.Transcoder; //导入方法依赖的package包/类
/**
* Write an SVG image to a file with the given transcoder to determine the
* format
*
* @param image
* the image
* @param output
* the file to write to
* @param trans
* the transcoder
* @throws IOException
* if an error occurs during writing
* @throws TranscoderException
* if an error occurs during transcoding
*/
public static void write(final SVGImage image, final File output, Transcoder trans) throws IOException,
TranscoderException
{
final TranscoderInput input = new TranscoderInput(image.createRenderer().getDocument());
final TranscoderOutput toutput = new TranscoderOutput(new FileOutputStream(output));
trans.transcode(input, toutput);
}