Loading image from code

Stimulsoft Reports.JAVA discussion
Post Reply
Lezenn
Posts: 12
Joined: Thu Jul 07, 2022 12:42 pm

Loading image from code

Post 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 ?
Vadim
Posts: 363
Joined: Tue Apr 23, 2013 11:23 am

Re: Loading image from code

Post by Vadim »

Hello.

Please use next code:

Code: Select all

((StiImage) report.GetComponentByName("Image1")).setImage(Base64.getEncoder().encodeToString(StiIOUtil.toByteArray(new FileInputStream(""))));
Lezenn
Posts: 12
Joined: Thu Jul 07, 2022 12:42 pm

Re: Loading image from code

Post by Lezenn »

It works, thanks !
Lech Kulikowski
Posts: 6238
Joined: Tue Mar 20, 2018 5:34 am

Re: Loading image from code

Post by Lech Kulikowski »

Hello,

You are welcome.
Post Reply