我正在使用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;
}
我已經通過代碼加強,以確保該值是正確的從數學和我甚至保存圖像文件出來,以確保縱橫比是正確的(它是)。不管我嘗試什麼,圖像都被壓扁了 - 就好像水晶報表設計器中的「縮放」值已關閉(它們不是)。預先感謝任何幫助!