这是我从This Link
获得的代码我希望用户上传图片然后调整大小.............
Public Sub ResizeFromStream(ByVal ImageSavePath As String, ByVal MaxSideSize As Integer, ByVal Buffer As System.IO.Stream)
Dim intNewWidth As Integer
Dim intNewHeight As Integer
Dim imgInput As System.Drawing.Image = System.Drawing.Image.FromStream(Buffer)
'Determine image format
Dim fmtImageFormat As ImageFormat = imgInput.RawFormat
'get image original width and height
Dim intOldWidth As Integer = imgInput.Width
Dim intOldHeight As Integer = imgInput.Height
'determine if landscape or portrait
Dim intMaxSide As Integer
If (intOldWidth >= intOldHeight) Then
intMaxSide = intOldWidth
Else
intMaxSide = intOldHeight
End If
If (intMaxSide > MaxSideSize) Then
'set new width and height
Dim dblCoef As Double = MaxSideSize / CDbl(intMaxSide)
intNewWidth = Convert.ToInt32(dblCoef * intOldWidth)
intNewHeight = Convert.ToInt32(dblCoef * intOldHeight)
Else
intNewWidth = intOldWidth
intNewHeight = intOldHeight
End If
'create new bitmap
Dim bmpResized As Drawing.Bitmap = New Drawing.Bitmap(imgInput, intNewWidth, intNewHeight)
'save bitmap to disk
bmpResized.Save(ImageSavePath, fmtImageFormat)
'release used resources
imgInput.Dispose()
bmpResized.Dispose()
Buffer.Close()
End Sub
现在,当我点击我的提交按钮时,它必须执行我的代码,但我不确定缓冲区字段的输入必须是什么?
Protected Sub btnUpload_Click() Handles btnUpload.Click
ResizeFromStream("~Pics", 200, ??????????)
End Sub
提前致谢!
修改 我需要从文件上传控件中获取我的图像!
答案 0 :(得分:0)
你可以像这样传递一个流对象:
Dim fs As New FileStream("C:\file.jpg", FileMode.Open)
ResizeFromStream("~Pics", 200, fs)
因此代码将在文件'file.jpg'上执行IO。这是一个非常粗略的例子,但正如Jon Skeet所问,图像来源的位置确实很重要。我的例子就是简单的“让你入门”类型。
答案 1 :(得分:0)
FileUpload.FileContent get是文件内容的流。