Page 1 of 1

Passing an Image as a variable

Posted: Wed Sep 13, 2006 11:17 pm
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

Passing an Image as a variable

Posted: Thu Sep 14, 2006 3:32 am
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.

Passing an Image as a variable

Posted: Fri Sep 15, 2006 8:45 am
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.