Protected Sub Upload_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Upload.Click
If Me.FileUpload1.HasFile Then
Dim intWidth, intHeight As Integer
Dim UlFileName, NewFileName As String
intWidth = 200 '*** Fix Width ***'
intHeight = 0 '*** If = 0 Auto Re-Cal Size ***'
'intHeight = 120
If Path.GetExtension(FileUpload1.FileName).ToLower <> ".gif" Then
'Pop Up. File needs to be a GIF
vLabel.Text = "Only .GIF files allowed. Please convert your image to a .GIF"
Else
UlFileName = "\\bk00app0001\Images\Temp_" & Me.ItemNumber.Text & "_" & Me.Year.Text & Path.GetExtension(FileUpload1.FileName).ToLower
'*** Save Images ***'
Me.FileUpload1.SaveAs(UlFileName)
NewFileName = "\\bk00app0001\Images\" & Me.ItemNumber.Text & "_" & Me.Year.Text & Path.GetExtension(FileUpload1.FileName).ToLower
Dim objGraphic As System.Drawing.Image = System.Drawing.Image.FromFile(UlFileName)
Dim objBitmap As Bitmap
'*** Calculate Height ***'
If intHeight > 0 Then
objBitmap = New Bitmap(objGraphic, intWidth, intHeight)
Else
If objGraphic.Width > intWidth Then
Dim ratio As Double = objGraphic.Height / objGraphic.Width
intHeight = ratio * intWidth
objBitmap = New Bitmap(objGraphic, intWidth, intHeight)
Else
objBitmap = New Bitmap(objGraphic)
End If
End If
'*** Save As ***'
objBitmap.Save(NewFileName, objGraphic.RawFormat)
'*** Close ***'
objGraphic.Dispose()
'*** Delete Original Image ***'
File.Delete(UlFileName)
'*** View Images ***'
Me.imgPicture.Visible = True
Me.imgPicture.ImageUrl = NewFileName
End If
End If
End Sub
上传图片后,它不会像网页上那样显示在网页上:
'*** View Images ***'
Me.imgPicture.Visible = True
Me.imgPicture.ImageUrl = NewFileName
谢谢!