Passing an Image as a variable

Stimulsoft Reports.NET discussion
Post Reply
DavidD
Posts: 1
Joined: Wed Sep 13, 2006 11:12 pm

Passing an Image as a variable

Post by DavidD »

I'd like to use a variable to pass an image into my report. Is this possible? I've tried declaring a variable of type object and setting it to the desired image (via a control's ToBitmap() method). That part works fine, but when I try to assign it to the StiImage component in the report (from within the Report.BeginRender), I get an InvalidCast exception. My BeginRender looks like this:

imgSketch.Image = (Image)SketchImage;

What am I doing wrong? Is there an easier way to pass the Image into the report without using a temporary file?

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

Passing an Image as a variable

Post by Edward »

DavidD wrote:I'd like to use a variable to pass an image into my report. Is this possible? I've tried declaring a variable of type object and setting it to the desired image (via a control's ToBitmap() method). That part works fine, but when I try to assign it to the StiImage component in the report (from within the Report.BeginRender), I get an InvalidCast exception. My BeginRender looks like this:

imgSketch.Image = (Image)SketchImage;

What am I doing wrong? Is there an easier way to pass the Image into the report without using a temporary file?

Thanks
David
You may use the following code:

Code: Select all

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

Code: Select all

if (MyImage is StiImage)
Image1.Image = (MyImage as StiImage).Image;
where MyImage - variable of Type Object in report's Dictionary.
Image1 - StiImage component on Report's page.
But this method does not show images in Designer. It shows only Images in rendered report.

Also you can load image to the StiImage component in the Report's Designer. For this you should select Image property of StiImage component. Then choose path to your image and press ok button and selected image will be stored in report code.

At latest build new Variable.ValueObject property is available.
So in latest build you may use the following code:

Code: Select all

report.Dictionary.Variables["MyImage"].ValueObject = Image.FromFile("d:\\SomeImage.jpg");
Please contact to Image to receive latest build.
Thank you.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Passing an Image as a variable

Post by Edward »

Latest version contains variables of type Image and very convenient Property Editor for StiImage component. You may specify variable or expression of type Image for the image in it, to load Image in report code in design time, to load Image from DataColumn, File or URL in run time.

Image

Thank you.
Post Reply