Page 1 of 1

Stretch Image only if too big

Posted: Tue Apr 19, 2016 9:40 am
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?

Re: Stretch Image only if too big

Posted: Wed Apr 20, 2016 8:37 am
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.

Re: Stretch Image only if too big

Posted: Thu Apr 21, 2016 1:28 pm
by Mekrwürd
Wow, thank you very much! Its works perfect :)

Re: Stretch Image only if too big

Posted: Fri Apr 22, 2016 9:11 am
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

Re: Stretch Image only if too big

Posted: Fri Apr 22, 2016 1:55 pm
by HighAley
Hello.

We need additional time to prepare an answer for you.

Thank you.

Re: Stretch Image only if too big

Posted: Mon Apr 25, 2016 9:38 am
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.