本文整理汇总了Java中org.apache.batik.transcoder.image.ImageTranscoder类的典型用法代码示例。如果您正苦于以下问题:Java ImageTranscoder类的具体用法?Java ImageTranscoder怎么用?Java ImageTranscoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ImageTranscoder类属于org.apache.batik.transcoder.image包,在下文中一共展示了ImageTranscoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createImage
import org.apache.batik.transcoder.image.ImageTranscoder; //导入依赖的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: getTestImageTranscoder
import org.apache.batik.transcoder.image.ImageTranscoder; //导入依赖的package包/类
/**
* Returns the <code>ImageTranscoder</code> the Test should
* use
*/
public ImageTranscoder getTestImageTranscoder(){
ImageTranscoder t = new InternalPNGTranscoder();
t.addTranscodingHint(PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE,
Boolean.FALSE);
t.addTranscodingHint(PNGTranscoder.KEY_BACKGROUND_COLOR,
new Color(0,0,0,0));
t.addTranscodingHint(PNGTranscoder.KEY_EXECUTE_ONLOAD,
Boolean.TRUE);
if (validate){
t.addTranscodingHint(PNGTranscoder.KEY_XML_PARSER_VALIDATING,
Boolean.TRUE);
t.addTranscodingHint(PNGTranscoder.KEY_XML_PARSER_CLASSNAME,
VALIDATING_PARSER);
}
if (userLanguage != null){
t.addTranscodingHint(PNGTranscoder.KEY_LANGUAGE,
userLanguage);
}
return t;
}
示例3: updateImage
import org.apache.batik.transcoder.image.ImageTranscoder; //导入依赖的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);
}
}
示例4: convert
import org.apache.batik.transcoder.image.ImageTranscoder; //导入依赖的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);
}
}
示例5: convert
import org.apache.batik.transcoder.image.ImageTranscoder; //导入依赖的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);
}
}
示例6: readInput
import org.apache.batik.transcoder.image.ImageTranscoder; //导入依赖的package包/类
protected void readInput(final PipelineContext context, final ProcessorInput input, Config config, OutputStream outputStream) {
try {
//JPEGTranscoder t = new JPEGTranscoder();
final ImageTranscoder imageTranscoder = new PNGTranscoder();
imageTranscoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(0.8));
//t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new Integer(100));
//trans.addTranscodingHint(JPEGTranscoder.KEY_AOI, aoi);
//Document document = readInputAsDOM4J(context, input);
//String documentString = XMLUtils.domToString(document);
//TranscoderInput ti = new TranscoderInput(new StringReader(documentString));
//TranscoderInput tixxx1 = new TranscoderInput(document);
final TranscoderInput transcoderInput = new TranscoderInput(new XMLReaderToReceiver() {
@Override
public void parse(String systemId) throws SAXException {
readInputAsSAX(context, (input != null) ? input : getInputByName(INPUT_DATA), createXMLReceiver());
}
});
final TranscoderOutput transcoderOutput = new TranscoderOutput(outputStream);
imageTranscoder.transcode(transcoderInput, transcoderOutput);
} catch (Exception e) {
throw new OXFException(e);
}
}
示例7: setupTranscoder
import org.apache.batik.transcoder.image.ImageTranscoder; //导入依赖的package包/类
private void setupTranscoder(ImageTranscoder t, SVGDocument doc) throws TranscoderException {
UserAgent userAgent = new UserAgentAdapter();
DocumentLoader loader = new DocumentLoader(userAgent);
BridgeContext ctx = new BridgeContext(userAgent, loader);
ctx.setDynamicState(BridgeContext.DYNAMIC);
GVTBuilder builder = new GVTBuilder();
GraphicsNode rootGN = builder.build(ctx, doc);
Rectangle2D bounds = rootGN.getBounds();
double pageWidth = settings.getPropertyDouble(PROPERTY_PAGE_WIDTH, DEFAULT_PAGE_WIDTH) * dpi;
double pageHeight = settings.getPropertyDouble(PROPERTY_PAGE_HEIGHT, DEFAULT_PAGE_HEIGHT) * dpi;
Point2D.Double scaledSize = getScaledSize(bounds.getWidth(), bounds.getHeight(), pageWidth, pageHeight);
System.out.println("Target size = " + pageWidth + "x" + pageHeight);
System.out.println("Scaled size = " + scaledSize.getX() + "x" + scaledSize.getY());
t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, (float) scaledSize.getX());
t.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, (float)scaledSize.getY());
t.addTranscodingHint(PNGTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER, 25.4f / 300.0f);
}
示例8: getTestImageTranscoder
import org.apache.batik.transcoder.image.ImageTranscoder; //导入依赖的package包/类
/**
* Returns the <code>ImageTranscoder</code> the Test should
* use
*/
public ImageTranscoder getTestImageTranscoder(){
ImageTranscoder t = super.getTestImageTranscoder();
t.addTranscodingHint(PNGTranscoder.KEY_ALTERNATE_STYLESHEET,
parameter);
return t;
}
示例9: getRasterizedSVG
import org.apache.batik.transcoder.image.ImageTranscoder; //导入依赖的package包/类
public BufferedImage getRasterizedSVG() {
if (rasterizedSVG != null) {
return rasterizedSVG;
}
try {
rasterizedSVG = new BufferedImage(
(int) Math.round(getPageSize().getWidth()), (int) Math.round(getPageSize().getHeight()),
BufferedImage.TYPE_INT_ARGB);
ImageTranscoder transcoder = new ImageTranscoder() {
@Override
public BufferedImage createImage(int width, int height) {
return rasterizedSVG;
}
@Override
public void writeImage(BufferedImage bufferedImage, TranscoderOutput transcoderOutput) throws TranscoderException {
}
};
transcoder.transcode(new TranscoderInput(getSVG()), null);
} catch (TranscoderException e) {
e.printStackTrace();
}
return rasterizedSVG;
}
示例10: internalRenderImage
import org.apache.batik.transcoder.image.ImageTranscoder; //导入依赖的package包/类
/**
* Renders the given image at the given size
* @param width
* @param height
* @return the new image
*/
@Override
protected BufferedImage internalRenderImage(int width, int height) throws TranscoderException {
RawTranscoderOutput output = new RawTranscoderOutput();
imageTranscoder.addTranscodingHint(ImageTranscoder.KEY_WIDTH, (float)width);
imageTranscoder.addTranscodingHint(ImageTranscoder.KEY_HEIGHT, (float)height);
imageTranscoder.transcode(source, output);
return output.getImage();
}
示例11: getPixelUnitToMillimeter
import org.apache.batik.transcoder.image.ImageTranscoder; //导入依赖的package包/类
/**
* Returns the pixel to millimeter conversion factor specified in the
* {@link TranscodingHints} or 0.3528 if any.
* @return the pixel unit to millimeter factor
*/
public float getPixelUnitToMillimeter() {
Object key = ImageTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER;
if (getTranscodingHints().containsKey(key)) {
return ((Float)getTranscodingHints().get(key)).floatValue();
} else {
// return 0.3528f; // 72 dpi
return UnitConv.IN2MM / 96; //96dpi = 0.2645833333333333333f;
}
}
示例12: actionPerformed
import org.apache.batik.transcoder.image.ImageTranscoder; //导入依赖的package包/类
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser =
new JFileChooser(makeAbsolute(currentSavePath));
fileChooser.setDialogTitle(resources.getString("ExportAsJPG.title"));
fileChooser.setFileHidingEnabled(false);
fileChooser.setFileSelectionMode
(JFileChooser.FILES_ONLY);
fileChooser.addChoosableFileFilter(new ImageFileFilter(".jpg"));
int choice = fileChooser.showSaveDialog(JSVGViewerFrame.this);
if (choice == JFileChooser.APPROVE_OPTION) {
float quality =
JPEGOptionPanel.showDialog(JSVGViewerFrame.this);
final File f = fileChooser.getSelectedFile();
BufferedImage buffer = svgCanvas.getOffScreen();
if (buffer != null) {
statusBar.setMessage
(resources.getString("Message.exportAsJPG"));
// create a BufferedImage of the appropriate type
int w = buffer.getWidth();
int h = buffer.getHeight();
final ImageTranscoder trans = new JPEGTranscoder();
if (application.getXMLParserClassName() != null) {
trans.addTranscodingHint
(JPEGTranscoder.KEY_XML_PARSER_CLASSNAME,
application.getXMLParserClassName());
}
trans.addTranscodingHint
(JPEGTranscoder.KEY_QUALITY, new Float(quality));
final BufferedImage img = trans.createImage(w, h);
// paint the buffer to the image
Graphics2D g2d = img.createGraphics();
g2d.setColor(Color.white);
g2d.fillRect(0, 0, w, h);
g2d.drawImage(buffer, null, 0, 0);
new Thread() {
public void run() {
try {
currentSavePath = f;
OutputStream ostream =
new BufferedOutputStream(new FileOutputStream(f));
trans.writeImage(img, new TranscoderOutput(ostream));
ostream.close();
} catch (Exception ex) { }
statusBar.setMessage
(resources.getString("Message.done"));
}
}.start();
}
}
}
示例13: getTestImageTranscoder
import org.apache.batik.transcoder.image.ImageTranscoder; //导入依赖的package包/类
/**
* Returns the <code>ImageTranscoder</code> the Test should
* use
*/
public ImageTranscoder getTestImageTranscoder(){
ImageTranscoder t = super.getTestImageTranscoder();
t.addTranscodingHint(PNGTranscoder.KEY_MEDIA, parameter);
return t;
}
示例14: createValidReferenceImage
import org.apache.batik.transcoder.image.ImageTranscoder; //导入依赖的package包/类
/**
* Helper method: creates a valid reference image
*/
public static URL createValidReferenceImage(String svgContent) throws Exception{
TranscoderInput validSrc = new TranscoderInput(new StringReader(svgContent));
File tmpFile = File.createTempFile(SVGRenderingAccuracyTest.TEMP_FILE_PREFIX,
SVGRenderingAccuracyTest.TEMP_FILE_SUFFIX);
TranscoderOutput validDst
= new TranscoderOutput(new FileOutputStream(tmpFile));
ImageTranscoder transcoder
= new PNGTranscoder();
transcoder.transcode(validSrc, validDst);
tmpFile.deleteOnExit();
return tmpFile.toURL();
}
示例15: rasterize
import org.apache.batik.transcoder.image.ImageTranscoder; //导入依赖的package包/类
public static BufferedImage rasterize(File svgFile) throws IOException {
final BufferedImage[] imagePointer = new BufferedImage[1];
// Rendering hints can't be set programatically, so
// we override defaults with a temporary stylesheet.
// These defaults emphasize quality and precision, and
// are more similar to the defaults of other SVG viewers.
// SVG documents can still override these defaults.
String css = "svg {" +
"shape-rendering: geometricPrecision;" +
"text-rendering: geometricPrecision;" +
"color-rendering: optimizeQuality;" +
"image-rendering: optimizeQuality;" +
"}";
File cssFile = File.createTempFile("batik-default-override-", ".css");
FileUtils.writeStringToFile(cssFile, css);
TranscodingHints transcoderHints = new TranscodingHints();
transcoderHints.put(ImageTranscoder.KEY_XML_PARSER_VALIDATING, Boolean.FALSE);
transcoderHints.put(ImageTranscoder.KEY_DOM_IMPLEMENTATION,
SVG12DOMImplementation.getDOMImplementation());
transcoderHints.put(ImageTranscoder.KEY_DOCUMENT_ELEMENT_NAMESPACE_URI,
SVGConstants.SVG_NAMESPACE_URI);
transcoderHints.put(ImageTranscoder.KEY_DOCUMENT_ELEMENT, "svg");
transcoderHints.put(ImageTranscoder.KEY_USER_STYLESHEET_URI, cssFile.toURI().toString());
try {
TranscoderInput input = new TranscoderInput(new FileInputStream(svgFile));
ImageTranscoder t = new ImageTranscoder() {
@Override
public BufferedImage createImage(int w, int h) {
return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
}
@Override
public void writeImage(BufferedImage image, TranscoderOutput out)
throws TranscoderException {
imagePointer[0] = image;
}
};
t.setTranscodingHints(transcoderHints);
t.transcode(input, null);
}
catch (TranscoderException ex) {
ex.printStackTrace();
throw new IOException("Couldn't convert " + svgFile);
}
finally {
cssFile.delete();
}
return imagePointer[0];
}