We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Remove transparency on PNG image

I’d like to set a white background on my XImage before saving it to an OutputStream, how would I go about doing that?


Here is my sample code:

Document doc = new Document(new File(“Images.pdf”));
Page page = this.doc.getPages().get_Item(1);
XImageCollection images = page.getResources().getImages();
OutputStream os = new BufferedOutputStream(new FileOutputStream(“image.png”));

images.get_Item(1).save(os, ImageType.getPng());

Using this code, it saves the image with a transparent background, but I would like to force a white background.

How would I go about doing this?
Thanks,
Tai



Hi Tai,


Thanks for your inquriy. We are looking into your requirement and will guide you accordingly.

Best Regards,

Just to provide some context, on why I need this:


I’m looking to replace Datalogics with Aspose.pdf, so I need to make sure that Aspose.pdf will be able to provide the same functionality as Datalogics currently does in our application. With Datalogics I am able to save the PNG with a white background.

Hi Tai,


Thanks for providing additional information. Please note Aspose.Pdf does not provide features to manipulate images. However we have another API Aspose.Imaging that can create and manipulate different image file formats. You can extract image from PDF using Aspose.Pdf and later can manipulate the image with Aspose.Imaging. I am moving your thread to Aspose.Imaging forum, there my Aspose.Imaging colleague will guide you properly.

We are sorry for the inconvenience caused.

Best Regards,
Hi Tai,

Thank you for your inquiry.

Aspose.Imaging API provides the feature to change the background color of a PNG image that has transparent background. Please visit the URL Changing Background color of a Transparent PNG Image for details on how to change the background color of a PNG image.

Feel free to contact us in case you have further query or comments.