Hello!
Things I did:
- create swing component which paints into SVGGraphics2D
- write the generated document to disk using the stream method of
SVGGraphics2D works fine. The generated file is readable by Squiggle GUI and transformable into
JPEG using Squiggle GUI too.
But i need to be independent from Squiggle GUI and try to use an
implementation similar to the one used by batik-rasterizer command line
interface.
Trying to use batik-rasterizer to transform my svg (generated with
SVGGraphics2D) into JPEG file fails with:
... org.apache.batik.transcoder.TranscoderException: null
Enclosed Exception:
Width (0) and height (0) cannot be <= 0
This is a bug, but really a fairly minor one since you almost always want to provide the w/h of the SVG (especially when generating a raster) otherwise it arbitrarily picks 400x400. See below for better ways to fix this.
I get the same error in my own code which should write a JPEG too. Trying to work around this by setting the missing values fails wit
ClassCastException.
I think you want to provide these hints to the PNGTranscoder not to the SVGGraphics2D. You can tell the svgGraphics2D what to set for width/height on the svg element it generates with:
setSVGCanvasSize(Dimension svgCanvasSize)
This is really what you want to do.
Good luck!
Code snippet:
HashMap map = new HashMap();
map.put(JPEGTranscoder.KEY_QUALITY, new Float(0.99));
map.put(ImageTranscoder.KEY_BACKGROUND_COLOR,
backgroundColor);
map.put(ImageTranscoder.KEY_HEIGHT, new Float(200));
map.put(ImageTranscoder.KEY_WIDTH, new Float(200));
svgGraphics2D.setRenderingHints(map);
Trying to use the method setRenderingHint inherited from
AbstractGraphics2D
public void setRenderingHint(RenderingHints.Key hintKey, Object
hintValue)
does not give me a hint which Keys i should use to prevent failing while
rasterizing.
How can i proceed to be able to read once written svg files without the
use of Squiggle GUI?
Thank you in advance!
Regards
Uwe
Attached a svg i generated with SVGGraphics2D
------------------------------------------------------------------------
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]