You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Jennifer Quesada <je...@firstfactory.com> on 2014/03/04 00:10:03 UTC

PPTX to PNG correct color rendering

Hello,

I am converting pptx slides to png by using POI library but it does not
render correctly the slide's colors, for example, instead of rendering
turquoise it will render gray. I tried to convert pptx slides to svg but
got the same problem, so I was wondering if it has something to do with
some settings somewhere.

*Code:*

> String file = "C:\\Users\\ABC\\demo1.pptx";XMLSlideShow ppt = null;
>
> ppt = new XMLSlideShow(OPCPackage.open(new File(file)));    Dimension pgsize = ppt.getPageSize();float scale = 1;int width = (int) (pgsize.width * scale);int height = (int) (pgsize.height * scale);
> XSLFSlide[] slide = ppt.getSlides();
> for (int i = 0; i < slide.length; i++) {
>     String title = slide[i].getTitle();
>
>     BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
>     Graphics2D graphics = img.createGraphics();
>
>     graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
>     graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
>     graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
>     graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
>     graphics.setColor(Color.white);
>     graphics.clearRect(0, 0, width, height);
>     graphics.scale(scale, scale);
>
>     slide[i].draw(graphics);
>
>     int sep = file.lastIndexOf(".");
>     String fname = file.substring(0, sep == -1 ? file.length() : sep) + "-" + (i + 1) +".png";
>
>     FileOutputStream out = new FileOutputStream(fname);
>     ImageIO.write(img, "png", out);
>     out.close();}
>
> Any help will be greatly appreciated!

Regards,
Jennifer