Stretch Image only if too big

Stimulsoft Reports.NET discussion
Post Reply
Mekrwürd
Posts: 3
Joined: Tue Apr 19, 2016 9:34 am

Stretch Image only if too big

Post by Mekrwürd »

Hi,

I want to include a user defined logo in my document. In order to make it look good, I need to stretch the image keeping the aspect Ratio.
This works fine if the Logo is too big. If the logo is small, it will get stretched and looks blurry. Is there a way to only stretch the image if it's too big?!

See my attached example. I tried using "can shrink" and it helps, but my image is not centered anymore (I guess the alignment counts for it's content in relation to the container width/height, so this makes sense)...

EDIT:
Maybe it's possible to do it with the "Before Print" event? If so, how to get the container width/height and image source width/height?
Attachments
LogoExample.mrt
Example file
(162.59 KiB) Downloaded 185 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Stretch Image only if too big

Post by HighAley »

Hello.

There is an Image property of the StiImage component where an image is stored. You could get the Width of the image in pixels. By default, we render images with 100dpi, so this value is equal to hundreds of Inches. To compare the image with the size of the component you could do this next way and disable the Stretch property. You should use next code in the Get Tag event, because the image could not be loaded yet in the Before Print event.

Code: Select all

var imageComp = (sender as StiImage);
if (imageComp.Image.Width<this.Unit.ConvertToHInches(imageComp.Width)) {
	imageComp.Stretch = false;
}
Thank you.
Mekrwürd
Posts: 3
Joined: Tue Apr 19, 2016 9:34 am

Re: Stretch Image only if too big

Post by Mekrwürd »

Wow, thank you very much! Its works perfect :)
Mekrwürd
Posts: 3
Joined: Tue Apr 19, 2016 9:34 am

Re: Stretch Image only if too big

Post by Mekrwürd »

Hi,

sorry, It only works when using a plain Image from file. Using Image Data like

Code: Select all

{Image.FromStream(new System.IO.MemoryStream(MyItem.FileContent))}
does not work. Is there any documentation on what variables (like sender) are available for each event + what exactly each event does?!

Edit:
Added an example Report
Attachments
data.zip
DataSet xml and xsd with the logo
(8.87 KiB) Downloaded 159 times
ExampleReport.mrt
Example report containing a logo set via "Image" and "Image Data" from dataset.
(15.72 KiB) Downloaded 256 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Stretch Image only if too big

Post by HighAley »

Hello.

We need additional time to prepare an answer for you.

Thank you.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Stretch Image only if too big

Post by HighAley »

Hello.

In this case you should use Get Image Data event with next code:

Code: Select all

var imageComp = (sender as StiImage);
if (e.Value.Width < this.Unit.ConvertToHInches(imageComp.Width))
{
    imageComp.Stretch = false;
};
Thank you.
Post Reply