Page 1 of 1

Loading image from code

Posted: Tue Aug 02, 2022 11:47 am
by Lezenn
Hi,

My objective is to be able to load a logo depending of an external content, only from java code.
I have some troubles when I want to load an image (png format) in my report, and export it into PDF.

My report has an image named "Image1", and I have this code to load the image file and set it to the right component. However, the image does not shows up.

Code: Select all

StiImage image = StiImageHelper.FromFile(this.getClass().getClassLoader().getResource("logo.png").getPath());
image.setWidth(64);
image.setHeight(64);
image.setAspectRatio(true);
image.setStretch(false);

((StiImage) report.GetComponentByName("Image1")).setImage(image);
Is my code right ?

Re: Loading image from code

Posted: Tue Aug 02, 2022 1:57 pm
by Vadim
Hello.

Please use next code:

Code: Select all

((StiImage) report.GetComponentByName("Image1")).setImage(Base64.getEncoder().encodeToString(StiIOUtil.toByteArray(new FileInputStream(""))));

Re: Loading image from code

Posted: Tue Aug 02, 2022 2:28 pm
by Lezenn
It works, thanks !

Re: Loading image from code

Posted: Wed Aug 03, 2022 8:25 am
by Lech Kulikowski
Hello,

You are welcome.