Crystal Reports Programmatic Image Resizing... Scale?
Posted
by C. Griffin
on Stack Overflow
See other posts from Stack Overflow
or by C. Griffin
Published on 2010-05-07T15:14:18Z
Indexed on
2010/05/07
15:18 UTC
Read the original article
Hit count: 622
I'm working with a Crystal Reports object in Visual Studio 2008 (C#). The report is building fine and the data is binding correctly. However, when I try to resize an IBlobFieldObject from within the source, the scale is getting skewed.
Two notes about this scenario. Source image is 1024x768, my max width and height are 720x576. My math should be correct that my new image size will be 720x540 (to fit within the max width and height guidelines). The ratio is wrong when I do this though:
img = Image.FromFile(path);
newWidth = img.Size.Width;
newHeight = img.Size.Height;
if ((img.Size.Width > 720) || (img.Size.Height > 576))
{
double ratio = Convert.ToDouble(img.Size.Width) / Convert.ToDouble(img.Size.Height);
if (ratio > 1.25) // Adjust width to 720, height will fall within range
{
newWidth = 720;
newHeight = Convert.ToInt32(Convert.ToDouble(img.Size.Height) * 720.0 / Convert.ToDouble(img.Size.Width));
}
else // Adjust height to 576, width will fall within range
{
newHeight = 576;
newWidth = Convert.ToInt32(Convert.ToDouble(img.Size.Width) * 576.0 / Convert.ToDouble(img.Size.Height));
}
imgRpt.Section3.ReportObjects["image"].Height = newHeight;
imgRpt.Section3.ReportObjects["image"].Width = newWidth;
}
I've stepped through the code to make sure that the values are correct from the math, and I've even saved the image file out to make sure that the aspect ratio is correct (it was). No matter what I try though, the image is squashed--almost as if the Scale values are off in the Crystal Reports designer (they're not). Thanks in advance for any help!
© Stack Overflow or respective owner