I've opened a bitmap from a jpg file with
Dim bmp As New Bitmap(IO.Path. Combine(origFol der, 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.co m 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(pr eviewFolder, value)) Then
Dim bmp As New Bitmap(IO.Path. Combine(origFol der, 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(tar getW), CInt(targetH),
Imaging.PixelFo rmat.Format24bp pRgb)
Dim g As Graphics = Graphics.FromIm age(bmp2)
g.Interpolation Mode = Drawing2D.Inter polationMode.Bi cubic
g.DrawImage(bmp , 0, 0, CInt(targetW), CInt(targetH))
bmp2.Save(IO.Pa th.Combine(prev iewFolder, value), Imaging.ImageFo rmat.Jpeg)
previewImage.Wi dth = Unit.Pixel(CInt (targetW))
previewImage.He ight = Unit.Pixel(CInt (targetH))
End If