设置图像的高度和宽度

时间:2012-02-08 20:33:15

标签: asp.net image height width

我使用下面的代码添加图片,我想设置图片的宽度和高度。

如何添加现有代码:

 Dim urls As New List(Of String)
 urls.Add("~/DownloadedImages/" & Session("tempDir").ToString & "/" & filename
 For Each imageURL As String In urls
 Me.FinalPreview.Controls.Add(New System.Web.UI.WebControls.Image() With {.ImageUrl = imageURL})
 Next imageURL

2 个答案:

答案 0 :(得分:1)

我不确定VB语法,但图像控件有一个高度和宽度属性,我认为它们将呈现为图像标记本身的heightwidth属性。因此,尝试在构造控件时以与指定ImageUrl属性相同的方式传递它们。

答案 1 :(得分:1)

     If btnBrowse.HasFile Then
        Dim fileName As String = ""

dim imgHeight为整数= 25 dim imgWeight as integer = 25

        fileName = Path.GetRandomFileName.Replace(".", " ") & ".png"
        lblImagePath.Text = ConfigurationManager.AppSettings("imgPath").ToString() & fileName
        If File.Exists(Server.MapPath("objectimages") & "/" & btnBrowse.FileName) Then
            File.Delete(Server.MapPath("objectimages") & "/" & btnBrowse.FileName)
        End If
        btnBrowse.SaveAs(Server.MapPath("objectimages") & "/" & btnBrowse.FileName)

        Dim image As Image = image.FromFile(Server.MapPath("objectimages") & "/" & btnBrowse.FileName)
        Dim thumbnailImage As Image = image.GetThumbnailImage(imgHeight , imgWeight , Nothing, IntPtr.Zero)
        '  Response.ContentType = "image/Jpeg/png/jpg"
        'thumbnailImage.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
        '  btnBrowse.SaveAs(Server.MapPath("objectimages") & "/" & btnBrowse.FileName)
        Dim bmp As Bitmap = CType(thumbnailImage, Bitmap)

        bmp.Save(Server.MapPath("objectimages") & "/" & fileName)

        bmp.Dispose()



    End If