RDLC报告比例图像对齐 [英] RDLC Reports Proportional Image Alignment

查看:189
本文介绍了RDLC报告比例图像对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究RDLC报告,我使用数据库图像,并将其大小类型设置为比例,如果图像的大小与边框不同,则边框不适合..这没关系,但是图像将根据边框左上方对齐,而我需要它在中心(在PDF上),而在IE上它居中..,这里是图像示例,请为此我需要帮助..



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



这是Desired One
http://up.g4z4.com/uploads/a3d2ca5b8e.jpg



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



谢谢,

解决方案

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



newWidth = cellheight * oldwidth / oldheight



newHeight = cellwidth * oldheight / oldwidth



CellWidth - NewWidth = 2x PaddingLeft



CellHeight - NewHeight = 2x PaddingTop



所以你现在需要做的只是将结果除以2并将其转换为整数。 / p>

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

 公共类ImageModel 
{
public int ImgId {get;组; }
public byte [] Blob {get;组; }

public string PaddingLeft
{
get
{
var img = byteArrayToImage(Blob);
//单元格宽度和高度必须以磅为单位指定
//(cellwidth - cellheight * image aspect ratio)/ 2
var result =(int)((256.0f - 256.0f * ((float)img.Width /(float)img.Height))/(float)2)+pt;
返回结果;
}
}
公共字符串PaddingTop
{
get
{
var img = byteArrayToImage(Blob);
var result =(int)((256.0f - 256.0f *((float)img.Height /(float)img.Width))/(float)2)+pt;
返回结果;

}
}

在此操作之后,我现在可以设置图像属性下的填充值如下:

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

希望有所帮助!



干杯;)


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,

解决方案

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 ;)

这篇关于RDLC报告比例图像对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆