Trouble adding image at ruuntime

Stimulsoft Reports.NET discussion
Post Reply
IanMcCarthy
Posts: 37
Joined: Wed Oct 11, 2006 3:44 am

Trouble adding image at ruuntime

Post by IanMcCarthy »

Once again I throw myself before the feet of the Stimulsoft developers...

I'm generating a report with an image of a chart on the first page.
The chart is generated from the application and saved to a file "chart.gif" (about 115K)
I can open the resultant file in numerous viewers/paint applications so I'm assumuing it's OK (also tried a bmp, that didn't work either).

In my application I:

Code: Select all

printReport = new StiReport();
printReport.Load(path);
StiPage page = printReport.Pages[0];

string imagePath = Path.GetTempFileName();
imagePath = Path.ChangeExtension(imagePath, CopyExport.DEFAULT_IMAGE_EXT);
CopyChartToFile(imagePath);
StiImage image = new StiImage();
image.Name = "CEL350ChartImage";
// Dummy size for now
image.ClientRectangle = new RectangleD(0, 0, 10, 10);

// This is a workaround for the FromFile function that keeps the file locked until
// the image is disposed of.
FileStream stream = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
image.Image = Image.FromStream(stream);
stream.Close();

File.Delete(imagePath);

page.Components.Add(image);
But print/preview/save all throw an exception:

'System.Runtime.InteropServices.ExternalException'
occurred in stimulsoft.report.dll
Additional information: A generic error occurred in GDI+.

What am I doing wrong this time?

Thanks, Ian

Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Trouble adding image at ruuntime

Post by Edward »

You can also use a variables of type Image in your report to resolve unknown issues. You can declare this variable in report and then you may to load any images in your report by assigning to this variable as well as saving them.
You can see the passing of image through variable in the following topic Example of using variables of type Image

Thank you.
IanMcCarthy
Posts: 37
Joined: Wed Oct 11, 2006 3:44 am

Trouble adding image at ruuntime

Post by IanMcCarthy »

Thick or what? I can't get that working either...

Any chance of an example?

In C# trying to:

Open existing report (just with headers/footers defined).
Create a new StiImage object.
Load image object with gif/jpg/bmp image from disk file.
Add image object to first page of report.

The current thinking is that the original report won't have an image object already in it, which is why I need to add "on-the-fly".

Thanks again.

Ian
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Trouble adding image at ruuntime

Post by Edward »

Please declare variable MyImage of type Image. Then save report to the file (MyImage.mrt).

For adding image in runtime you should use the following code:

Code: Select all

            StiReport report = new StiReport();
            report.Load("MyImage.mrt");

            StiImage im = new StiImage();
            im.Image = Image.FromFile("MyImage.jpg");
            report.Compile();
            report["MyImage"] = im.Image;
            report.Show();
Thank you.
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Trouble adding image at ruuntime

Post by Vital »

Strange probem. If you use different images problem exist?

Thank you.
Post Reply