本文整理匯總了Java中org.apache.batik.transcoder.TranscoderOutput類的典型用法代碼示例。如果您正苦於以下問題:Java TranscoderOutput類的具體用法?Java TranscoderOutput怎麽用?Java TranscoderOutput使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TranscoderOutput類屬於org.apache.batik.transcoder包,在下文中一共展示了TranscoderOutput類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createImage
import org.apache.batik.transcoder.TranscoderOutput; //導入依賴的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();
}
示例2: convertSvgToPng
import org.apache.batik.transcoder.TranscoderOutput; //導入依賴的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);
}
}
示例3: streamOut
import org.apache.batik.transcoder.TranscoderOutput; //導入依賴的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();
}
}
示例4: transcodeToSVG
import org.apache.batik.transcoder.TranscoderOutput; //導入依賴的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;
}
示例5: saveImage
import org.apache.batik.transcoder.TranscoderOutput; //導入依賴的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();
}
}
示例6: transcode
import org.apache.batik.transcoder.TranscoderOutput; //導入依賴的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);
}
示例7: getReferenceImageData
import org.apache.batik.transcoder.TranscoderOutput; //導入依賴的package包/類
/**
* Returns the reference image for this test.
*/
protected byte [] getReferenceImageData() {
try {
BufferedImage img = new BufferedImage
(400, 400, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = img.createGraphics();
g2d.setColor(Color.blue);
g2d.fillRect(0, 0, 400, 400);
g2d.setColor(Color.red);
g2d.fillRect(100, 50, 100, 50);
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
PNGTranscoder t = new PNGTranscoder();
TranscoderOutput output = new TranscoderOutput(ostream);
t.writeImage(img, output);
return ostream.toByteArray();
} catch (Exception ex) {
throw new RuntimeException("BackgroundColorTest error");
}
}
示例8: getReferenceImageData
import org.apache.batik.transcoder.TranscoderOutput; //導入依賴的package包/類
/**
* Returns the reference image for this test.
*/
protected byte [] getReferenceImageData() {
try {
BufferedImage img = new BufferedImage
(400, 400, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = img.createGraphics();
g2d.setColor(Color.black);
g2d.fillRect(0, 0, 400, 400);
g2d.setColor(Color.red);
g2d.drawRect(100, 50, 100, 50);
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
PNGTranscoder t = new PNGTranscoder();
TranscoderOutput output = new TranscoderOutput(ostream);
t.writeImage(img, output);
return ostream.toByteArray();
} catch (Exception ex) {
throw new RuntimeException("DOMTest error");
}
}
示例9: loadSvg
import org.apache.batik.transcoder.TranscoderOutput; //導入依賴的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();
}
示例10: generate
import org.apache.batik.transcoder.TranscoderOutput; //導入依賴的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");
}
示例11: getImage
import org.apache.batik.transcoder.TranscoderOutput; //導入依賴的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;
}
示例12: updateImage
import org.apache.batik.transcoder.TranscoderOutput; //導入依賴的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);
}
}
示例13: transcode
import org.apache.batik.transcoder.TranscoderOutput; //導入依賴的package包/類
@Override
protected void transcode(Document document, String uri, TranscoderOutput output) throws TranscoderException {
super.transcode(document, uri, output);
int w = (int) (width + 0.5);
int h = (int) (height + 0.5);
curTxf.translate(translateX, translateY);
ImageRenderer renderer = createImageRenderer();
renderer.updateOffScreen(w, h);
renderer.setTransform(curTxf);
renderer.setTree(this.root);
this.root = null; // We're done with it...
try {
Shape raoi = new Rectangle2D.Float(0, 0, width, height);
// Warning: the renderer's AOI must be in user space
renderer.repaint(curTxf.createInverse().createTransformedShape(raoi));
bufferedImage = renderer.getOffScreen();
} catch (Exception ex) {
throw new TranscoderException(ex);
}
}
示例14: convertSvgToPng
import org.apache.batik.transcoder.TranscoderOutput; //導入依賴的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();
}
示例15: updateImage
import org.apache.batik.transcoder.TranscoderOutput; //導入依賴的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);
}
}