【问题标题】:Set height and width of an Image设置图像的高度和宽度
【发布时间】:2012-03-01 08:07:33
【问题描述】:

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

如何添加到现有代码:

 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

【问题讨论】:

    标签: asp.net image height width


    【解决方案1】:

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

    【讨论】:

    • @kprobst-感谢您的回复,我已经按照您说的尝试了,但没有成功!
    【解决方案2】:
         If btnBrowse.HasFile Then
            Dim fileName As String = ""
    

    将 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
    

    【讨论】:

      猜你喜欢
      • 2014-06-21
      • 2016-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-14
      相关资源
      最近更新 更多