im4java Convert svg to png, keep transparent background

1.2k views Asked by At

I'm using the im4java library to convert svg files to png files. I want the transparent backgrounds to remain transparent but they always become white. This is the operation I'm using:

IMOperation hdpiOperation = new IMOperation();
hdpiOperation.addImage();
hdpiOperation.background("none");
hdpiOperation.addImage();

If I manually try with ImageMagick from the commandline using this command it does work:

convert -background none a.svg b.png

Any ideas?

1

There are 1 answers

0
barti_ddu On BEST ANSWER

Since im4java appends parameters in method execution order, you can move hdpiOperation.background("none") call before image placeholders to mimic working 'raw' command:

hdpiOperation.background("none");
hdpiOperation.addImage();
hdpiOperation.addImage();