469,126 Members | 1,256 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,126 developers. It's quick & easy.

w3wp keeps hold of bitmap(fromFile)

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
Nov 21 '05 #1
2 1436
"Andrew Morton" <ak*@in-press.co.uk.invalid> schrieb:
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()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
Herfried K. Wagner [MVP] wrote:
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
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by jay | last post: by
8 posts views Thread by Paul Loveless | last post: by
3 posts views Thread by John Dann | last post: by
1 post views Thread by The Confessor | last post: by
12 posts views Thread by Lee | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.