473,545 Members | 2,358 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 1573
"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
11925
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
10531
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...
8
7421
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
6682
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
1258
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...
2
4256
by: GT | last post by:
Could someone please explain how to add images to a ListView other than in the first column?
1
4308
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
4024
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
4215
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...
0
7487
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7934
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7446
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7778
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5349
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...
0
4966
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...
0
3476
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...
0
3459
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.