如何在SSRS报表中动态调整图像的高度和宽度?

时间:2019-04-22 14:14:06

标签: sql-server ssrs-2012

我想基于表达式在SSRS报告中动态调整图像的高度和宽度,但是图像尺寸属性中没有可用的表达式选项,它仅采用数字值。 我想像下面的C#代码一样调整图像大小。   私有void GetImageSize(字符串路径)         {             尝试             {                 System.Drawing.Image图片= System.Drawing.Image.FromFile(路径);                 如果(图片!= null)                 {                     System.Drawing.Image imageResize =(((System.Drawing.Image)image.Clone());                     int resizeWidth = 0;                     int resizeHeight = 0;                     bool heightIsLongerDimension =(imageResized.Height> imageResized.Width);                     float heightInches =(float)(imageResized.Height / imageResized.VerticalResolution);                     float widthInches =(float)(imageResized.Width / imageResized.Horizo​​ntalResolution);

Syntax.syntaxARQ

2 个答案:

答案 0 :(得分:0)

如果单击图像框,然后单击鼠标右键,将看到属性选项。 您可以单击图像,然后单击F4,将显示属性窗口。 那里有大小选项。您将在此处看到各种选项。默认情况下,会自动选择按比例拟合。 您可能需要更改它以适合大小。 这将自动调整图像大小。 同样在下面的链接将帮助您更多细节。看看它。 https://www.tutorialgateway.org/display-image-in-ssrs-report/

答案 1 :(得分:0)

在报表中使用自定义代码来定义以下vb.net函数:

Public Function ResizeImage(ByVal picbytes as Byte()) As  Byte()
    Try

       Dim ms as System.IO.MemoryStream = Nothing
       Dim rms as System.IO.MemoryStream
       Dim bm as System.Drawing.Bitmap

       ms = new System.IO.MemoryStream(picbytes)
       bm = new System.Drawing.Bitmap(ms)

        Dim newWidth As Integer
        Dim newHeight As Integer

            Dim originalWidth As Integer =bm.Width
            Dim originalHeight As Integer = bm.Height
            Dim percentWidth As Single = CSng(1280) / CSng(originalWidth)
            Dim percentHeight As Single = CSng(960) / CSng(originalHeight)
            Dim percent As Single = IIf(percentHeight < percentWidth, percentHeight, percentWidth)
            newWidth = CInt(originalWidth * percent)
            newHeight = CInt(originalHeight * percent)


        Dim newImage As System.Drawing.Image = New System.Drawing.Bitmap(newWidth, newHeight)
        Using graphicsHandle As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(newImage)
            graphicsHandle.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
            graphicsHandle.DrawImage(bm, 0, 0, newWidth, newHeight)
        End Using

        Dim ms2 = new  System.IO.MemoryStream()
        newImage.Save(ms2, System.Drawing.Imaging.ImageFormat.Jpeg) 
        Dim bytes = ms2.ToArray()

        Return bytes

    Catch ex As Exception
        Return nothing
    End Try
End Function

参考报告System.Drawing .NET程序集。

然后您可以在表达式中重用函数,例如:

Code.ResizeImage(Fields!Bild.Value)