Resize my image on upload not working - what must my buffer be?

Posted by Etienne on Stack Overflow See other posts from Stack Overflow or by Etienne
Published on 2009-06-26T11:43:05Z Indexed on 2010/03/19 5:01 UTC
Read the original article Hit count: 193

Filed under:
|
|
|

This is the code i got from This Link

I want the user to upload a picture and then resize it.............

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

Now when i click on my submit button it must execute my code but i am not sure what the input must be for the Buffer field?

Protected Sub btnUpload_Click() Handles btnUpload.Click

     ResizeFromStream("~Pics", 200, ??????????)

End Sub

Thanks in advanced!

Edit I need to get my Image from the File Upload control!

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about vb.net