代码之家  ›  专栏  ›  技术社区  ›  Trilochan Sahu

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

  •  0
  • Trilochan Sahu  · 技术社区  · 5 年前

    我想根据表达式在SSRS报告中动态调整图像的高度和宽度,但是在图像大小属性中没有表达式选项,它只接受数值。 我想把我的图片调整到c代码下面。 { 尝试 System.Drawing.Image Image=System.Drawing.Image.FromFile(路径); 如果(图像!=空) { System.Drawing.Image imageResized=((System.Drawing.Image)Image.Clone()); int resizeWidth=0; int resizeHeight=0; 浮点高度英寸=(浮点)(imageResized.Height/imageResized.VerticalResolution);

                    if (heightIsLongerDimension)
                    {
                        resizeHeight = (int)(imageResized.VerticalResolution * 3);
                        //resizeWidth = Convert.ToInt32((((heightInches - 3) / heightInches) * widthInches) * imageResized.HorizontalResolution);
                        resizeWidth = Convert.ToInt32((((float)imageResized.Width) / (float)imageResized.Height) * imageResized.HorizontalResolution) * 3;
                    }
                    else
                    {
                        resizeWidth = (int)(imageResized.HorizontalResolution * 3);
                        //resizeHeight = Convert.ToInt32((((widthInches - 3) / widthInches) * heightInches) * imageResized.VerticalResolution);
                        resizeHeight = Convert.ToInt32((((float)imageResized.Height) / (float)imageResized.Width) * imageResized.VerticalResolution) * 3;
                    }
                    //image height and width set in pixel
                    Image1.Height = resizeHeight;
                    Image1.Width = resizeWidth;
                    //image height and width set in inches
                    float width = (float)(Math.Round((resizeWidth / imageResized.HorizontalResolution), 1));
                    float height = (float)(Math.Round((resizeHeight / imageResized.VerticalResolution), 1));
                }
            }
            catch
            {
                throw;
            }
        }
    
    0 回复  |  直到 5 年前
        1
  •  0
  •   AnkUser    5 年前

    如果单击“图像”框并右键单击,将看到“属性”选项。 你可以点击图片,然后点击F4属性窗口将显示。 您可能需要将其更改为适合大小。 下面的链接也将帮助你更详细。看看吧。 https://www.tutorialgateway.org/display-image-in-ssrs-report/

        2
  •  0
  •   Wojciech Iłowiecki    5 年前

    在报表中使用自定义代码定义以下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
    

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

    Code.ResizeImage(Fields!Bild.Value)