w3wp keeps hold of bitmap(fromFile)

A

Andrew Morton

I've opened a bitmap from a jpg file with
Dim bmp As New Bitmap(IO.Path.Combine(origFolder, value))
' now resize the image into another bitmap and save that

where origFolder is the directory containg the image and value is its
filename. This works, but w3wp.exe seems to keep a handle on it even when
the aspx.vb page has finished running and the browser is closed. (I can't
delete the file in Windows Explorer and Process Explorer from
sysinternals.com says it's w3wp.exe.)

I looked in the help and found Image.Dispose(), but it comes with a note
that "This member supports the .NET Framework infrastructure and is not
intended to be used directly from your code."

What VB.NET 2003 code /should/ I use to tell it to let go of the file?

Andrew


The rest of the code operating on the bitmap:-

If Not File.Exists(IO.Path.Combine(previewFolder, value)) Then
Dim bmp As New Bitmap(IO.Path.Combine(origFolder, value))
Dim w As Double = CDbl(bmp.Width)
Dim h As Double = CDbl(bmp.Height)
Dim targetW As Double = 440
Dim targetH As Double = 330
' what aspect ratio do we want?
Dim aspect As Double = w / h
If aspect >= targetW / targetH Then
' targetW is correct, adjust targetH
targetH = CInt(targetW / aspect)
Else
' target height is correct, adjust width
targetW = CInt(targetH * aspect)
End If
Dim bmp2 As New Bitmap(CInt(targetW), CInt(targetH),
Imaging.PixelFormat.Format24bppRgb)
Dim g As Graphics = Graphics.FromImage(bmp2)
g.InterpolationMode = Drawing2D.InterpolationMode.Bicubic
g.DrawImage(bmp, 0, 0, CInt(targetW), CInt(targetH))
bmp2.Save(IO.Path.Combine(previewFolder, value), Imaging.ImageFormat.Jpeg)
previewImage.Width = Unit.Pixel(CInt(targetW))
previewImage.Height = Unit.Pixel(CInt(targetH))
End If
 
H

Herfried K. Wagner [MVP]

Andrew Morton said:
I've opened a bitmap from a jpg file with
Dim bmp As New Bitmap(IO.Path.Combine(origFolder, value))
' now resize the image into another bitmap and save that

where origFolder is the directory containg the image and value is its
filename. This works, but w3wp.exe seems to keep a handle on it even when
the aspx.vb page has finished running and the browser is closed. (I can't
delete the file in Windows Explorer and Process Explorer from
sysinternals.com says it's w3wp.exe.)

I looked in the help and found Image.Dispose(), but it comes with a note
that "This member supports the .NET Framework infrastructure and is not
intended to be used directly from your code."

Note that the 'Dispose' method is overloaded and the comment you posted only
applies to the 'Dispose(Boolean)' overload. This means that it's safe (and
recommended) to call a 'Bitmap' object's 'Dispose' method if it isn't needed
any more:

\\\
Dim b As New Bitmap(...)
....
b.Dispose()
///
 
A

Andrew Morton

Herfried said:
Note that the 'Dispose' method is overloaded and the comment you
posted only applies to the 'Dispose(Boolean)' overload. This means
that it's safe (and recommended) to call a 'Bitmap' object's
'Dispose' method if it isn't needed any more:

\\\
Dim b As New Bitmap(...)
...
b.Dispose()
///

Thank you, Herfried. That works perfectly.

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top