RDLC 报告比例图像对齐

发布于 2025-01-05 03:52:23 字数 536 浏览 2 评论 0原文

我正在制作 RDLC 报告,我使用数据库图像,并将其大小类型设置为比例,如果图像的大小与边框不完全相同,则边框不适合..这是可以的,但是图像将根据边框在左上角对齐,而我需要它居中(在 PDF 上),而在 IE 上它居中..,这里是图像示例,,请我需要帮助..

这是我已经拥有了 http://up.g4z4.com/uploads/f1fdee3542.jpg

这个是理想的人 http://up.g4z4.com/uploads/a3d2ca5b8e.jpg

我读过一次RDLC 报告中的图像来源或注册点位于左上角,这就是为什么它显示为这样的原因..但是写此信息的人说他不确定..这可能吗?或者它与无法更改的默认对齐方式有关?

谢谢你,

I'm working on an RDLC Report ,I use a DB Image, and set it's size type to Proportional, if the image isn't the exact size as it's borders, borders won't fit .. this is ok, but the image will be aligned top-left according to borders while I need it to be centered (on PDF) while on IE it's centered .., here are image examples,, Please I Need Help for this ..

This is the I Already Have
http://up.g4z4.com/uploads/f1fdee3542.jpg

This is the Desired One
http://up.g4z4.com/uploads/a3d2ca5b8e.jpg

I read once that the image origin or Registration Point in RDLC Reports is on the top left, that's why it shows like this .. but the one who wrote that said he's not sure about it .. is this possible? or is it related to a default alignment that can't be changed?

Thank you,

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

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

发布评论

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

评论(2

蘑菇王子 2025-01-12 03:52:23

对于每个图像,我们可以找出其宽高比或高度/宽度。
假设您的单元格已知宽度和高度,您可以确定它是否太窄或太短。此外,您可以使用以下公式计算其新宽度和高度:

newWidth = cellheight*oldwidth/oldheight

newHeight = cellwidth*oldheight/oldwidth

CellWidth - NewWidth = 2x PaddingLeft

CellHeight - NewHeight = 2x PaddingTop

因此,您现在所需要做的就是将结果除以 2 并将其转换为整数。

我在主报告的 SubReportProcessing 事件中为数据库中的每个图像实现了以下 getter(我实际上是从 sqlite 数据库中提取这些图像),我只需将所有图像添加为数据源。

public class ImageModel
{
    public int ImgId { get; set; }
    public byte[] Blob { get; set; }

    public string PaddingLeft
    {
        get
        {
            var img = byteArrayToImage(Blob);
            //cell width and height must be specified in points
            //(cellwidth - cellheight * image aspect ratio) / 2 
            var result = (int)((256.0f - 256.0f * ((float)img.Width / (float)img.Height)) / (float)2) + "pt";
            return result;
        }
    }
    public string PaddingTop
    {
        get
        {
            var img = byteArrayToImage(Blob);
            var result = (int)((256.0f - 256.0f * ((float)img.Height / (float)img.Width)) / (float)2) + "pt";
            return result;

        }
    }

完成该操作后,我现在可以在图像属性下设置填充值,如下所示:

=Fields!PaddingLeft.Value
=Fields!PaddingTop.Value

希望有帮助!

干杯;)

For every image we can find out its aspect ratio either width/height or height/width.
Assuming that your cell has known width and height you can determine if its going to be too narrow or too short. Moreover you can calculate its new width and height with following formulas:

newWidth = cellheight*oldwidth/oldheight

newHeight = cellwidth*oldheight/oldwidth

CellWidth - NewWidth = 2x PaddingLeft

CellHeight - NewHeight = 2x PaddingTop

So all you need to do now is just divide the result by 2 and cast it onto an integer.

I implemented following getters for each image in database(I am actually pulling these images from sqlite database) in the SubReportProcessing Event for my main report I simply add all my images as DataSource.

public class ImageModel
{
    public int ImgId { get; set; }
    public byte[] Blob { get; set; }

    public string PaddingLeft
    {
        get
        {
            var img = byteArrayToImage(Blob);
            //cell width and height must be specified in points
            //(cellwidth - cellheight * image aspect ratio) / 2 
            var result = (int)((256.0f - 256.0f * ((float)img.Width / (float)img.Height)) / (float)2) + "pt";
            return result;
        }
    }
    public string PaddingTop
    {
        get
        {
            var img = byteArrayToImage(Blob);
            var result = (int)((256.0f - 256.0f * ((float)img.Height / (float)img.Width)) / (float)2) + "pt";
            return result;

        }
    }

After that operation I can now set padding value under image properties as follows:

=Fields!PaddingLeft.Value
=Fields!PaddingTop.Value

Hope that helps!

Cheers ;)

噩梦成真你也成魔 2025-01-12 03:52:23

I'm looking for an answer to this as well; I found this code which does the trick (it works) but it's not very generic (depends on a hard coded page width). With a little work this code could work.

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