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