Page 1 of 1
Load image from file in application code - where do I find Image.FromFile() ?
Posted: Wed Apr 14, 2010 11:45 am
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?
Load image from file in application code - where do I find Image.FromFile() ?
Posted: Wed Apr 14, 2010 12:46 pm
by Jan
Hello,
You need add System.Drawing namespace.
Thank you.
Load image from file in application code - where do I find Image.FromFile() ?
Posted: Wed Apr 14, 2010 4:38 pm
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.
Load image from file in application code - where do I find Image.FromFile() ?
Posted: Wed Apr 14, 2010 5:24 pm
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?
Load image from file in application code - where do I find Image.FromFile() ?
Posted: Fri Apr 23, 2010 7:34 am
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.