我正在使用Visual Studio 2008(C#)中的Crystal Reports对象。报告构建正常,数据绑定正确。但是,当我尝试从源代码中调整IBlobFieldObject的大小时,它会发生偏斜。Crystal Reports编程图像调整大小...比例?
有关此方案的两点注意事项。源图像是1024x768,我的最大宽度和高度是720x576。我的数学应该是正确的,我的新图像尺寸将为720x540(以适应最大宽度和高度指南)。该比率是错误的,当我这样做虽然:
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;
}
我已经通过代码加强,以确保该值是正确的从数学和我甚至保存图像文件出来,以确保纵横比是正确的(它是)。不管我尝试什么,图像都被压扁了 - 就好像水晶报表设计器中的“缩放”值已关闭(它们不是)。预先感谢任何帮助!