Free Support Forum - aspose.com

Adding java BufferedImage as a Picture to a Slide

I'm just investigating using Aspose.Slides in our application to produce PPT files and have downloaded the demo programs and started using it. I've hit a problem that I hope someone has already dealt with...

We create custom images in our Java application using code like that below:

BufferedImage im= new BufferedImage(sizeX , sizeY, BufferedImage.TYPE_INT_ARGB);

Graphics2D temp = im.createGraphics();

paint(temp); // paints objects and text

I'd like to then use this image to populate a aspose.slides.Picture object, but the only public method is to pass it an InputStream. I don't want to have to write my image out to a temporary file and create an InputStream to get it back.

Are there any plans on implementing a Picture constructor that lets me pass in a java Image class instead?

A problem I'm having with this method is that the portions of the image that I did not paint anything onto are becoming opaque when I write it to a GIF file using ImageIO. When this is then added as a Picture, the background comes out black in the slide - for example, when I'm drawing a circle, the result is a circle inside a black square, rather then a nice circle image with transparent background. I'm sure this is a problem with how I'm writing the image to the GIF file, which I'd like to avoid in the first place anyway - however any alternate solution needs to deal with this transparency problem too. My guess is I have to pick a color I don't plan to use, fill the image background with it, then declare that color to be tranparent to Aspose software - just haven't tried that yet.

Thanks in advance for any ideas you have.


This message was posted using Page2Forum from Technical Articles - Aspose.Slides for .NET and Java

Dear mass,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for considering Aspose.Slides.

If I am not mistaken, InputStream can also be stream from memory not just from file. If it is so, then you don’t need to write image out to a temporary file. I will let you know about it.

Hello Maas,

Most probably all your problems just because of GIF format. You should remember,
MS PowerPoint uses only 2 types of images Jpeg and Png. Save image in Png format
if you need transparency or high quality image and in Jpeg format in other cases.

Thanks for the tip. I'll look into this.

Looks like I can use an ImageIO.write() method - writing to an OutputStream, then maybe use some sort of IO pipe class to route it back to an Input Stream - haven't found that combination yet.

The reminder to use PNG format was also very helpful - thanks. I've never written png files, but I'm assuming ImageIO will handle it.

Thanks for your help - I'll keep working on it.

Robin