RDLC Reports Proportional Image Alignment

ぃ、小莉子 提交于 2019-12-23 17:48:05

问题


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,


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/9258225/rdlc-reports-proportional-image-alignment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!