Last post Aug 26, 2009 11:20 AM by xr280xr
Aug 18, 2009 10:23 AM|Sam42|LINK
I need to get the height and width of an image that is in a directory on the server. I have been doing it by createing a bitmap and then checking the height and width of the bitmap and then disposing it. But for some reason something lingers and if I do
it twice in quick succession then I get an error.
Is there a better way to do this? I am thinking I need to do it once when the image is uploaded to the server and then store the height and width in a database for later use. Is there a simpler or better way than this?
Aug 18, 2009 12:21 PM|lohith.bn|LINK
Dim imageurl As String = Server.MapPath("/uploads/" + filename) Dim fullSizeImg As System.Drawing.Image = System.Drawing.Image.FromFile(imageurl) Dim width As Integer = fullSizeImg.Width Dim height As Integer = fullSizeImg.Height
Aug 18, 2009 12:28 PM|lohith.bn|LINK
Aug 26, 2009 11:20 AM|xr280xr|LINK
Any chance you're reassigning your Bitmap reference to a new Bitmap before disposing it? I had an issue once where I created a Bitmap bmp from a file. I then did something like bmp = bmp.GetThumbnailImage() which left the filestream to the original file
open. It is strange that the class does not close the filestream before returning to the caller.
Also there are some alternatives to using GDI+, such as reading file properties, here: