Image in pdf is distorted when using BufferedImage vs InputStream

Hi,


I am trying to add an image using BufferedImage and the image looks distorted. InputStream displays the image correctly but, the image loading takes longer time.

We store the image in a local storage so, I am interested to load the image in bytes rather than bits.

Please suggest how to get the best performance for loading images.

Thanks,
Mary

Hi Mary,

Thanks for your inquriy. I have created two PDF documents form an image using BufferedImage and InputStream with Aspose.Pdf for Java 11.7.0, but I am afraid I am unable to notice any difference. I will appreciate it if you please share your sample code along with image to replicate the issue at our end.

BufferedImage img = ImageIO.read(new File(myDir + "Aspose.Jpg"));

Document doc1 = new Document();
com.aspose.pdf.Page page1 = doc1.getPages().add();
com.aspose.pdf.Image image1 = new com.aspose.pdf.Image();
image1.setBufferedImage(img);
page1.getParagraphs().add(image1);
doc1.save(myDir + "Image_bufferedimage.pdf");

Document doc = new Document();
Page page = doc.getPages().add();
java.io.FileInputStream fs = new java.io.FileInputStream(myDir + "Aspose.Jpg");
com.aspose.pdf.Image image = new com.aspose.pdf.Image();
image.setImageStream(fs);
page.getParagraphs().add(image);
doc.save(myDir + "Image_inputstream.pdf");

We are sorry for the incovneince cuased.

Best Regards,

Hi,


Attached is an image with distorted when I use BufferedImage and clean when using InputStream.

Please suggest.

Thanks,
Mary


Hi Mary,


Thanks for your feedback. I have tried the scenario with a sample barcode image but I am afraid I am unable to notice the reported issue. Please share your sample code along with source image here, we will look into it and will guide you accordingly.

We are sorry for the inconvenience.

Best Regards,