Validate Dimensions of Uploaded Image : ASP.NET

Function validateDimension() As Boolean

            Dim imageBytes(imageupload.PostedFile.InputStream.Length) As Byte
            Dim stream As System.IO.Stream = imageupload.PostedFile.InputStream
            stream.InitializeLifetimeService()
            stream.Read(imageBytes, 0, imageBytes.Length)
            Dim imagedata As System.Drawing.Image = System.Drawing.Image.FromStream(stream)
            Dim imageWidth As Integer = imagedata.PhysicalDimension.Width  'PhysicalDimension.Height
            Dim imageHeight As Integer = imagedata.PhysicalDimension.Height
            If imageWidth >= 200 And imageHeight >= 200 Then
                Return True
            Else
                Return False
            End If
    End Function

2 comments:

  1. why would you return true if you catch an exception?

    ReplyDelete
  2. Thanx 4 pointing out the prob.. :)

    ReplyDelete