1

I'm using the Batik conversion code as Vaadin suggests however I need to make the background of the PNG image transparent because it can be displayed in containers of different colors and I don't want the white border to show. I've tried everything I can think of and I can't seem to find a way to make the background of the PNG transparent. I've even tried to force the background color to help Batik but it doesn't work:

chart.getConfiguration().getChart().setBackgroundColor(new SolidColor("#FFFFFF"));

I've then tried combinations (either, or both) of:

pngTranscoder.addTranscodingHint(PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE, Boolean.TRUE);
pngTranscoder.addTranscodingHint(PNGTranscoder.KEY_BACKGROUND_COLOR, java.awt.Color.WHITE);

And nothing seems to work. Any suggestions on how to do this would be greatly appreciated.

Stephane Grenier
  • 15,527
  • 38
  • 117
  • 192
  • 3
    Did you try `new SolidColor(255, 255, 255, 0.0)` - the last is the Alpha value, the opacity, where 1.0 would be fully opaque, 0.0 totally transparent. Or `new Color(0x00FFFFFF, true)` – Joop Eggen Nov 20 '17 at 12:14
  • I was dealing with two issues apparently. Yes that definitely did the trick. Also it's important to state that the pngTranscoder code should be removed. If you want to answer the question I'll accept yours as the answer – Stephane Grenier Nov 20 '17 at 12:36

1 Answers1

1

There are two colors set:

new SolidColor(255, 255, 255, 0.0)

the last is the Alpha value, the opacity, where 1.0 would be fully opaque, 0.0 totally transparent.

And the actual color:

new Color(0x00FFFFFF, true)

with the constructor for RGBA.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • nitpicking: so it's ARGB? – cfrick Nov 20 '17 at 16:31
  • @cfrick **:)** the java API and javadoc is also not very consistent; in [Color](https://docs.oracle.com/javase/8/docs/api/java/awt/Color.html#Color-int-boolean-) the mention is from rgba. In little endian it would be bgra. – Joop Eggen Nov 20 '17 at 16:43