473,809 Members | 2,819 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

w3wp keeps hold of bitmap(fromFile )

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
Nov 21 '05 #1
2 1581
"Andrew Morton" <ak*@in-press.co.uk.inv alid> schrieb:
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."


Note that the 'Dispose' method is overloaded and the comment you posted only
applies to the 'Dispose(Boolea n)' 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(Boolea n)' 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
11962
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 GraphicsPath along with it. How do I save it all in a single file? Or how do I "glue" graphicspath to bitmap so they save together? thanks,
1
10618
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, meaning; I don't want to save the image header, only the pixels data. the raw data should be saved in a byte array. The direct way is to do a loop over the image pixels and to copy pixel by pixel to the byte array. I'm looking for another way to...
8
7431
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 objImageFormat.Equals(Imaging.ImageFormat.Bmp) Then Me.ImageFormat = "BMP"
2
6700
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 don't get an exception but it appears the Bitmap is blank. Can anyone share some knowledge on this?
3
1272
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 pre-existing bitmap and then resave the bitmap. I've tried several ways of doing this but they either don't work or give errors. Anyone able to help me out please? The sort of thing I'm doing is: Dim MyBMP as Bitmap =...
2
4269
by: GT | last post by:
Could someone please explain how to add images to a ListView other than in the first column?
1
4316
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 On disallows implicit conversions from 'System.Drawing.Image' to 'System.Drawing.Bitmap'.
12
4049
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
4225
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 Memory" error with some others. The strange thing is that when I try to add the icon manually to the imageList, it adds it without problems!! One of the icons that generates this problem is:
0
10635
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9198
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7653
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3013
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.