Re: How to convert svg with css into PNG image?
Hi Meccain, 赵刚 mecc...@gmail.com wrote on 11/11/2010 04:26:38 AM: I am try to convert the svg with css into image, however, I haven't got a way to convert the expected, the css style is lost in the converted image .The test code is as following, the rect should be with fill color, however, the converted image doesn't have the fill color String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; [...] Element defs = doc.createElement(defs); You need to use 'createElementNS(svgNS, element name)' instead of just createElement(element name). If you just use createElement you will not get SVG elements, so they won't be rendered (the problem was more than just CSS). This applies to every place you create an element. Thomas DeWeese | CDG Advanced Development | Eastman Kodak Company | 343 State Street | Rochester, NY 14650-0128 | thomas.dewe...@kodak.com | 585 724-0294 | www.kodak.com svgRoot.appendChild(defs); Element style = doc.createElement(style); style.setAttribute(type, text/css); style.setAttribute(MEDIA,screen); style.appendChild(doc.createTextNode(@media screen{\n.graphic {fill:#99;}\n})); defs.appendChild(style); Element rect = doc.createElement(rect); rect.setAttribute(class, graphic); rect.setAttribute(x, 0); rect.setAttribute(y, 0); rect.setAttribute(width, 100); rect.setAttribute(height, 50); svgRoot.appendChild(rect); ImageTranscoder coder = new PNGTranscoder(); coder.addTranscodingHint(ImageTranscoder.KEY_MEDIA, screen); SVGTranscoder coder2 = new SVGTranscoder(); TranscoderInput input = new TranscoderInput(doc); OutputStream ostream = null; try { ostream = new FileOutputStream(out.png ); TranscoderOutput output = new TranscoderOutput(ostream); coder.transcode(input, output); try { Writer writer = new FileWriter( out.svg ); TranscoderOutput output2 = new TranscoderOutput(writer); coder2.transcode(input, output2); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TranscoderException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { ostream.flush(); ostream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Dimensions are too large exception
I am trying to convert a wmf image into a jpg image, my code looks like /***code ***/ ImageInfo info = imageManager.getImageInfo(uri, sessionContext); if(pictName.equals(image22.wmf)){ info.getSize(); String S = PAWAN; } //Load image and request Graphics2D image g2dImage = (ImageBuffered)imageManager. getImage(info, ImageFlavor.BUFFERED_IMAGE, sessionContext); g2dImage.getBufferedImage().getHeight(); g2dImage.getRenderedImage().getHeight(); g2dImage.getSize().setSizeInPixels (info.getSize().getWidthPx(), info.getSize().getHeightPx()); OutputStream os = unit.getStreamProvider().createFile(pictName+.jpg); ImageIO.write(g2dImage.getRenderedImage(), jpg, os); /***end code***/ while this works for half of the sample size that I have. For the other half, I get a Dimensions are too large exception exception, the stack trace is /** stack trace / java.lang.IllegalArgumentException: Dimensions (width=851968 height=65536) are too large at java.awt.image.SampleModel.init(SampleModel.java:112) at java.awt.image.SinglePixelPackedSampleModel.init(SinglePixelPackedSampleModel.java:124) at java.awt.image.Raster.createPackedRaster(Raster.java:770) at java.awt.image.Raster.createPackedRaster(Raster.java:466) at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1015) at java.awt.image.BufferedImage.init(BufferedImage.java:315) at org.apache.batik.transcoder.wmf.tosvg.AbstractWMFPainter.getImage(Unknown Source) at org.apache.batik.transcoder.wmf.tosvg.WMFPainter.paint(Unknown Source) at org.apache.fop.image.loader.batik.ImageConverterWMF2G2D$Graphics2DImagePainterWMF.paint(ImageConverterWMF2G2D.java:98) at org.apache.xmlgraphics.image.loader.impl.ImageConverterG2D2Bitmap.paintToBufferedImage(ImageConverterG2D2Bitmap.java:149) at org.apache.xmlgraphics.image.loader.impl.ImageConverterG2D2Bitmap.convert(ImageConverterG2D2Bitmap.java:74) at org.apache.xmlgraphics.image.loader.pipeline.ImageProviderPipeline.execute(ImageProviderPipeline.java:175) at org.apache.xmlgraphics.image.loader.pipeline.ImageProviderPipeline.execute(ImageProviderPipeline.java:99) at org.apache.xmlgraphics.image.loader.ImageManager.getImage(ImageManager.java:227) at org.apache.xmlgraphics.image.loader.ImageManager.getImage(ImageManager.java:294) at net.thirdwing.util.ImageUtils.copyImage(ImageUtils.java:73) /** end stack trace / I tried looking at AbstractWMFPainter's getImage method where I guess this size is calculated. That code is way too complicated for me to understand :(. Is there a way to get this working or to downsize for large images?. Thanks, -Watte
Re: Minimum acceptable/desired Java version and related thoughts
Hi everyone, In the scope of bug 46434 [1], I believe it was highly desired to have user feedback about this. It's great to see user expressing their feedback, thanks! :-) FYI, Java 5 is already end of life as well, http://java.sun.com/j2se/1.5/ Yeah, but Java for Business releases will be supported for up to eight years from initial release date [1], which means that 1.5 should still be around for a few years more. ;-) Cheers Tonny Kohar Cheers, Helder [1] http://www.oracle.com/us/technologies/java/java-for-business-071123.html - To unsubscribe, e-mail: batik-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: batik-users-h...@xmlgraphics.apache.org