473,395 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 1566
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jay | last post by:
I have a bitmap and a graphicspath object. I draw pixels on m_Bitmap and I'm drawing text using m_Graphics GraphicsPath object. However, saving my work with m_Bitmap.Save doesn't save...
1
by: Sharon | last post by:
I have 2 questions that are just the opposite to one another: (1) I need to read an image file (like bitmap, jpeg etc.) and to save only its data, I need to save his data in a raw data format,...
8
by: Paul Loveless | last post by:
Hi all, I've written the following code to retrieve the file format of an image file: Dim objImageFormat As ImageFormat objImageFormat = Me.SourceImage.RawFormat If...
2
by: active | last post by:
I find Bitmap.Save works for WMF files but Bitmap.FromFile does not. If I use FromFile on a WMF file that came with VS I get an exception. If I use it on a WMF file created with Bitmap.Save I...
3
by: John Dann | last post by:
I've never had much cause to read up in detail on GDI+ but there's a small piece of a project where I need to add some annotation (let's say just some small filled rectangles as markers) to a...
2
by: GT | last post by:
Could someone please explain how to add images to a ListView other than in the first column?
1
by: The Confessor | last post by:
The following code: MapGraphics(ListBox_Graphics.SelectedIndex - 1).MapBitmap = System.Drawing.Bitmap.FromFile(OpenFileDialog_SelectFile.FileName) incurs the following error: Option Strict...
12
by: Lee | last post by:
I have the following code using System; using System.Windows.Forms; using System.Drawing; using System.Collections; namespace FINN {
1
by: Dana | last post by:
I tried loading an icon to an imageList using the following method: Image cc = Bitmap.FromFile("C:\\myicon.ico"); imageList1.Images.Add(cc); It works with some icons but generates an "Out of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.