locked
Image resizing help RRS feed

  • Question

  • User690522074 posted
    I'm trying to resize an image as it uploads, and even though the file is successfully being uploaded, the image is not being resized...any suggestions on why not?
    thanks
    
    
     If fpl1.PostedFile IsNot Nothing AndAlso fpl1.PostedFile.FileName <> "" Then
    Dim strExtension As String = System.IO.Path.GetExtension(fpl1.FileName)
    If (strExtension.ToUpper() = ".JPG") Or (strExtension.ToUpper() = ".GIF") Then
    ' Resize Image Before Uploading to DataBase
    Dim imageToBeResized As System.Drawing.Image = System.Drawing.Image.FromStream(fpl1.PostedFile.InputStream)
    Dim imageHeight As Integer = imageToBeResized.Height
    Dim imageWidth As Integer = imageToBeResized.Width
    Dim maxHeight As Integer = 20
    Dim maxWidth As Integer = 20
    imageHeight = (imageHeight * maxWidth) / imageWidth
    imageWidth = maxWidth

    If imageHeight > maxHeight Then
    imageWidth = (imageWidth * maxHeight) / imageHeight
    imageHeight = maxHeight
    End If

    Dim bitmap As New Bitmap(imageToBeResized, imageWidth, imageHeight)

    bitmap.Save(path)

    End If
    Monday, June 13, 2011 12:42 PM

Answers