本文整理匯總了Java中org.apache.batik.transcoder.TranscoderException類的典型用法代碼示例。如果您正苦於以下問題:Java TranscoderException類的具體用法?Java TranscoderException怎麽用?Java TranscoderException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TranscoderException類屬於org.apache.batik.transcoder包,在下文中一共展示了TranscoderException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: convertSvgToPng
import org.apache.batik.transcoder.TranscoderException; //導入依賴的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);
}
}
示例2: streamOut
import org.apache.batik.transcoder.TranscoderException; //導入依賴的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();
}
}
示例3: transcodeToSVG
import org.apache.batik.transcoder.TranscoderException; //導入依賴的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;
}
示例4: load
import org.apache.batik.transcoder.TranscoderException; //導入依賴的package包/類
@Override
public ImageFrame load(int imageIndex, int width, int height, boolean preserveAspectRatio, boolean smooth)
throws IOException {
if (0 != imageIndex) {
return null;
}
int imageWidth = width > 0 ? width : DEFAULT_SIZE;
int imageHeight = height > 0 ? height : DEFAULT_SIZE;
try {
return createImageFrame(imageWidth, imageHeight, getPixelScale());
} catch (final TranscoderException ex) {
throw new IOException(ex);
}
}
示例5: createImageFrame
import org.apache.batik.transcoder.TranscoderException; //導入依賴的package包/類
@NotNull
private ImageFrame createImageFrame(final int width, final int height, final float pixelScale)
throws TranscoderException {
final BufferedImage bufferedImage = getTranscodedImage(width * pixelScale, height * pixelScale);
final ByteBuffer imageData = getImageData(bufferedImage);
return new FixedPixelDensityImageFrame(ImageStorage.ImageType.RGBA, imageData, bufferedImage.getWidth(),
bufferedImage.getHeight(), getStride(bufferedImage), null, pixelScale, null);
}
示例6: parse
import org.apache.batik.transcoder.TranscoderException; //導入依賴的package包/類
@Override
public boolean parse(XMLSlideShow xmlSlideShow, XSLFSlide xslfSlide, JSONObject object) {
try {
XSLFPictureData xslfPictureData = xmlSlideShow.addPicture(parserHelper.getImage(object, "image/png",
readSvg(object.getString("svg"))), PictureData.PictureType.PNG);
XSLFPictureShape xslfPictureShape = xslfSlide.createPicture(xslfPictureData);
xslfPictureShape.setAnchor(parserHelper.getRectangle(object));
parserHelper.rotate(xslfPictureShape, object);
return true;
} catch (IOException | TranscoderException e) {
logger.warn(e, "解析SVG圖片[{}]時發生異常!", object.toJSONString());
return false;
}
}
示例7: convert
import org.apache.batik.transcoder.TranscoderException; //導入依賴的package包/類
public List<File> convert() throws IOException, TranscoderException {
List<File> generated;
if (outCfg.getInputFile() != null) {
File input = FileUtil.newFile(outCfg.getInputFile());
generated = convertFile(input, outCfg);
} else {
File dir = FileUtil.newFile(outCfg.getInputDirectory());
@SuppressWarnings("unchecked")
Collection<File> listFiles = (Collection<File>)FileUtils.listFiles(dir, new String[]{"svg"}, true);
generated = new ArrayList<>();
for (File file : listFiles) {
generated.addAll(convertFile(file, outCfg));
}
}
return generated;
}
示例8: transcode
import org.apache.batik.transcoder.TranscoderException; //導入依賴的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);
}
示例9: getImage
import org.apache.batik.transcoder.TranscoderException; //導入依賴的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;
}
示例10: updateImage
import org.apache.batik.transcoder.TranscoderException; //導入依賴的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);
}
}
示例11: transcode
import org.apache.batik.transcoder.TranscoderException; //導入依賴的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);
}
}
示例12: saveAsANY
import org.apache.batik.transcoder.TranscoderException; //導入依賴的package包/類
/**
* Save a file trying to auto-guess the file type.
*
* @param file File name
* @param width Width (for pixel formats)
* @param height Height (for pixel formats)
* @param quality Quality (for lossy compression)
* @throws IOException on file write errors or unrecognized file extensions
* @throws TranscoderException on transcoding errors
* @throws TransformerFactoryConfigurationError on transcoding errors
* @throws TransformerException on transcoding errors
* @throws ClassNotFoundException when the transcoder was not installed
*/
public void saveAsANY(File file, int width, int height, double quality) throws IOException, TranscoderException, TransformerFactoryConfigurationError, TransformerException, ClassNotFoundException {
String extension = FileUtil.getFilenameExtension(file);
if("svg".equals(extension)) {
saveAsSVG(file);
}
else if("pdf".equals(extension)) {
saveAsPDF(file);
}
else if("ps".equals(extension)) {
saveAsPS(file);
}
else if("eps".equals(extension)) {
saveAsEPS(file);
}
else if("png".equals(extension)) {
saveAsPNG(file, width, height);
}
else if("jpg".equals(extension) || "jpeg".equals(extension)) {
saveAsJPEG(file, width, height, quality);
}
else {
throw new IOException("Unknown file extension: " + extension);
}
}
示例13: updateImage
import org.apache.batik.transcoder.TranscoderException; //導入依賴的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);
}
}
示例14: transcode
import org.apache.batik.transcoder.TranscoderException; //導入依賴的package包/類
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);
ImageRenderer renderer = createImageRenderer();
renderer.updateOffScreen(w, h);
// curTxf.translate(0.5, 0.5);
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);
}
}
示例15: load
import org.apache.batik.transcoder.TranscoderException; //導入依賴的package包/類
@Override
public ImageFrame load(int imageIndex, int width, int height, boolean preserveAspectRatio, boolean smooth)
throws IOException {
if (0 != imageIndex) {
return null;
}
int imageWidth = width > 0 ? width : DEFAULT_SIZE;
int imageHeight = height > 0 ? height : DEFAULT_SIZE;
try {
return createImageFrame(imageWidth, imageHeight, getPixelScale());
} catch (TranscoderException ex) {
throw new IOException(ex);
}
}