472,119 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

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 1512
"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 leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.