Stretch Image only if too big
Stretch Image only if too big
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?
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
Re: Stretch Image only if too big
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.
Thank you.
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;
}
Re: Stretch Image only if too big
Wow, thank you very much! Its works perfect 

Re: Stretch Image only if too big
Hi,
sorry, It only works when using a plain Image from file. Using Image Data like
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
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))}
Edit:
Added an example Report
- Attachments
-
- data.zip
- DataSet xml and xsd with the logo
- (8.87 KiB) Downloaded 160 times
-
- ExampleReport.mrt
- Example report containing a logo set via "Image" and "Image Data" from dataset.
- (15.72 KiB) Downloaded 257 times
Re: Stretch Image only if too big
Hello.
We need additional time to prepare an answer for you.
Thank you.
We need additional time to prepare an answer for you.
Thank you.
Re: Stretch Image only if too big
Hello.
In this case you should use Get Image Data event with next code:
Thank you.
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;
};