我正在使用Visual Studio 2008(C#)中的Crystal Reports对象。报告构建良好,数据绑定正确。但是,当我尝试从源代码调整IBlobFieldObject大小时,比例会失真。
关于此情况有两点需要注意。源图像为1024x768,我的最大宽度和高度为720x576。我的计算应该是正确的,即我的新图像尺寸将为720x540(以符合最大宽度和高度的指南)。但是当我这样做时比例就不对了。
关于此情况有两点需要注意。源图像为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;
}
我已经逐步检查代码,确保从数学上计算出的值是正确的,并且甚至保存了图像文件以确保其宽高比正确(确实如此)。无论我尝试什么,图像都被压缩了——几乎像是Crystal Reports设计者中的比例值错误一样(但它们并不是)。非常感谢您提前的帮助!