Load image from file in application code - where do I find Image.FromFile() ?

Stimulsoft Reports.NET discussion
Post Reply
haarrrgh
Posts: 13
Joined: Wed Apr 14, 2010 8:10 am

Load image from file in application code - where do I find Image.FromFile() ?

Post by haarrrgh »

I want to load an image from a file at runtime, in my C# code where I open the report.

I downloaded the user manual and on page 81, I found the following:
Also it is possible to load images from a code of application before report rendering:

Code: Select all

StiReport report = new StiReport();
report.Load("D:\\myimage.mrt");
StiImage image = new StiImage();
image.Image = Image.FromFile("d:\\SomeImage.jpg");
report.Compile();
report["MyImage"] = image;
report.Show();

I wanted to try this in my application, but I can't find Image.FromFile().

Can someone tell me in which namespace I can find this?
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Load image from file in application code - where do I find Image.FromFile() ?

Post by Jan »

Hello,

You need add System.Drawing namespace.

Thank you.
haarrrgh
Posts: 13
Joined: Wed Apr 14, 2010 8:10 am

Load image from file in application code - where do I find Image.FromFile() ?

Post by haarrrgh »

Thank you, that's it!
I didn't realize that the .net namespace was meant - I was looking for an Image class inside the Stimulsoft assemblies.
haarrrgh
Posts: 13
Joined: Wed Apr 14, 2010 8:10 am

Load image from file in application code - where do I find Image.FromFile() ?

Post by haarrrgh »

Another problem: even if I've found the Image class now, I'm not able to load an image at runtime.

Do I have to do anything different if I want to .Render() and .ExportDocument() instead of .Show() ?

I tried the following:

Code: Select all

...
rep.RegData(ds);

StiImage img = new StiImage();
img.Image = System.Drawing.Image.FromFile(@"c:\test.gif");

rep.Compile();
rep["Image1"] = img;

rep.Render();
rep.ExportDocument(StiExportFormat.Pdf, @"c:\test.pdf");
"Image1" is an empty image control on the Report Title Band.



I also tried what I found in the Developer FAQ, chapter 8.13 (page 38):

Code: Select all

StiImage img = rep.GetComponents()["Image1"] as StiImage;
img.Image = System.Drawing.Image.FromFile(@"c:\test.gif");

rep.Render();
Or the second way:

Code: Select all

rep.Compile();

StiImage img = rep.GetComponents()["Image1"] as StiImage;
img.ImageToDraw = System.Drawing.Image.FromFile(@"c:\test.gif");

rep.Render();

No matter what I do, the result is always the same: the report is exported, but the image is not in it.

What am I doing wrong?
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

Load image from file in application code - where do I find Image.FromFile() ?

Post by Ivan »

Hello,

Please use the following code:

Code: Select all

            StiReport report = new StiReport();
            report.Load("D:\\myimage.mrt");
            StiImage image = (StiImage)report.GetComponentByName("Image1");
            image.Image = Image.FromFile("c:\\test.gif");
            report.Compile();
            report.Show();
Thank you.
Post Reply