This is a migrated thread and some comments may be shown as answers.

Resize PictureBox with User Function

2 Answers 446 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 1
Aaron asked on 26 Oct 2015, 09:21 PM

Hi,

I'm using Telerik Reporting 9.015.324 (VS 2015, Windows 10 x64).  I have a PictureBox in the Detail section of my report.  I have its Value property set to a string field in my data source - "ImagePath" - which is returning file paths.  The images are different sizes and proportions and I need them all to fit within the margins of the report.  Additionally, there is a TextBox in the Detail section with text content returned by the data source - "Content".  I'm trying to use a User Function to enforce a maximum Height and/or Width on the PictureBox based on the actual Height/Width of the image file.

This is my height function:

public static int GetPictureBoxHeightFromImagePath(string imagePath)
{
    Image img = Image.FromFile(imagePath);
    return img.Height;
}

That user function is bound to the Height property of the PictureBox.

When I preview my report I get an "Out of memory" exception almost immediately.

I'm curious as to why I'm getting this exception, but my main objective is to get my report images to fit within the report.

I'm open to other approaches.

Thanks much.

 
 

2 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 28 Oct 2015, 04:18 PM
Hello Aaron,

You can use the PictureBox.Sizing Property and use a suitable ImageSizeMode for your scenario. For example, the AutoSize image size mode seems suitable since it grows or shrinks the borders of the PictureBox item to fit the image.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Aaron
Top achievements
Rank 1
answered on 28 Oct 2015, 04:47 PM

Hi Nasko,

 

I can't use AutoSize because some of the images are too large to fit within the margins of the report.  When I print the report or save it to a PDF it cuts off the end of these images.  I need a way to shrink the image itself to fit the margins of the report while preserving the original image's proportions.

 

Thanks,

Aaron

Tags
General Discussions
Asked by
Aaron
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Aaron
Top achievements
Rank 1
Share this question
or