Crystal Reports 程序化图像大小调整...缩放?

发布于 2024-08-31 21:19:36 字数 1189 浏览 1 评论 0原文

我正在 Visual Studio 2008 (C#) 中使用 Crystal Reports 对象。报告构建良好,数据绑定正确。但是,当我尝试从源内部调整 IBlobFieldObject 的大小时,比例变得倾斜。

关于此场景的两个注释。源图像是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 设计器中的比例值被关闭一样(事实并非如此)。预先感谢您的任何帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

潜移默化 2024-09-07 21:19:36

Crystal Reports 处理 IBlobFieldObject 的方式存在几个问题。我遇到的第一个问题是内联文档对于 Crystal Reports 的 ReportObjects 的高度和宽度属性不正确。它说这些值以缇为单位,但事实并非如此。例如:

ImageReport imgRpt = new ImageReport();
// The following value should be in PIXELS... NOT twips as the docs suggest!
imgRpt.Section3.ReportObjects["image"].Height = 300;

第二个问题与我正在进行的 imageToByteArray 转换有关。这是我使用的方法:

    public byte[] imageToByteArray(System.Drawing.Image imageIn)
    {
        MemoryStream ms = new MemoryStream();
        // The following line was ImageFormat.Jpeg, but it caused sizing issues
        // in Crystal Reports.  Changing to ImageFormat.Bmp made the squashed
        // problems go away.
        imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
        return ms.ToArray();
    }

总而言之,Crystal Reports 似乎更喜欢使用 ImageFormat.Bmp 来填充 IBlobFieldObjects。现在,如果有人可以告诉我如何修复使用 ImageFormat.Bmp 的可怕位深度(这很可能是 Crystal Reports 报表对象处理图像数据的方式,并且可能无法修复),我就准备好了。

There are several problems with the way Crystal Reports handles IBlobFieldObjects. The first problem that I had was that the inline documentation was incorrect for a Crystal Reports' ReportObjects' Height and Width properties. It says that the values are stated in twips, which they AREN'T. For example:

ImageReport imgRpt = new ImageReport();
// The following value should be in PIXELS... NOT twips as the docs suggest!
imgRpt.Section3.ReportObjects["image"].Height = 300;

The second problem had to do with the imageToByteArray conversion I was doing. Here is the method I was using:

    public byte[] imageToByteArray(System.Drawing.Image imageIn)
    {
        MemoryStream ms = new MemoryStream();
        // The following line was ImageFormat.Jpeg, but it caused sizing issues
        // in Crystal Reports.  Changing to ImageFormat.Bmp made the squashed
        // problems go away.
        imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
        return ms.ToArray();
    }

In summation, it appears that Crystal Reports prefers ImageFormat.Bmp for filling IBlobFieldObjects. Now if somebody could tell me how to fix the awful bitdepth of using ImageFormat.Bmp (it's most likely the way that the Crystal Reports Report object handles the image data, and may not be fixable), I'd be all set.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文