From f8dd89a164228d28afd6080fb37e1f94b3e30a09 Mon Sep 17 00:00:00 2001 From: Luis Bernardo Date: Thu, 3 Apr 2014 21:57:51 +0000 Subject: FOP-2339: GIF to PS transparency is black; patch by Simon Steiner git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1584420 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/render/ps/PSImageHandlerRenderedImage.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/java/org') diff --git a/src/java/org/apache/fop/render/ps/PSImageHandlerRenderedImage.java b/src/java/org/apache/fop/render/ps/PSImageHandlerRenderedImage.java index d943f1ce8..6b5745e86 100644 --- a/src/java/org/apache/fop/render/ps/PSImageHandlerRenderedImage.java +++ b/src/java/org/apache/fop/render/ps/PSImageHandlerRenderedImage.java @@ -19,9 +19,12 @@ package org.apache.fop.render.ps; +import java.awt.Color; import java.awt.Dimension; +import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; import java.awt.image.ColorModel; import java.awt.image.RenderedImage; import java.io.IOException; @@ -63,6 +66,17 @@ public class PSImageHandlerRenderedImage implements PSImageHandler { Rectangle2D targetRect = new Rectangle2D.Double(x, y, w, h); RenderedImage ri = imageRend.getRenderedImage(); + + if (ri instanceof BufferedImage && ri.getColorModel().hasAlpha()) { + BufferedImage convertedImg = new BufferedImage(ri.getWidth(), ri.getHeight(), BufferedImage.TYPE_INT_RGB); + Graphics2D g = (Graphics2D) convertedImg.getGraphics(); + g.setBackground(Color.WHITE); + g.clearRect(0, 0, ri.getWidth(), ri.getHeight()); + g.drawImage((BufferedImage)ri, 0, 0, null); + g.dispose(); + ri = convertedImg; + } + ImageEncoder encoder = ImageEncodingHelper.createRenderedImageEncoder(ri); Dimension imgDim = new Dimension(ri.getWidth(), ri.getHeight()); String imgDescription = ri.getClass().getName(); -- cgit v1.2.3