Any help appreciated.
(VB.NET under XP and Vista, SP1 installed)
My code, inherited from a VB6 version of an app that ran under W98,
loads an image from a file into a PictureBox. The user may want to
move or delete the file that is being shown. The corresponding event-
driven code for "delete this picture" uses:
My.Computer.Fil eSystem.DeleteF ile(sPath)
The exception which is thrown tells me that the system cannot access
the file as it's "being used by another process". What other process?
(There is no multithreading in the app.) Presumably this means that
you can't do anything with a jpg image file while it's being displayed
in a PictureBox (whereas you could with VB6/W98). Annoying, but I
decided on a workaround that meant blanking out the PictureBox before
attempting to delete the file. I've experimented with several methods,
including loading a new image from a different (dummy) jpg file,
setting the Image property to a bitmap created on the fly, or just
doing this before the delete:
frmMainForm.pic Preview.Image.D ispose()
Still no luck - or rather, sometimes the deletion takes place without
problems, but most of the time it throws an exception, and if you loop
around and try again and again for a minute or two, usually the
exceptions just keep on coming. Still more mysteriously, tests suggest
that the system finally frees up the image file for deletion after a
few seconds in some cases (counting from where the PictureBox is
loaded with another image), or after a few minutes in others.
Can anyone figure out what's going on?
(I know that in theory you could dispense with the PictureBox
completely and just display the image using GDI+ graphics methods on
the form surface, but there are various reasons why implementing such
a solution would be hugely time-consuming for this app.) 4 5594
Gerard,
What is hugely time-consuming with drawing an Image on the surface, I am
not aware of the fact that after the scene is another method used for
drawing on the picturebox background surface.
Beside that does this simple code work for me.
PictureBox1.Loa d("d:\test.jpg" )
IO.File.Delete( "d:\test.jp g")
Cor
<ge************ @yahoo.comschre ef in bericht
news:93******** *************** ***********@m36 g2000hse.google groups.com...
Any help appreciated.
(VB.NET under XP and Vista, SP1 installed)
My code, inherited from a VB6 version of an app that ran under W98,
loads an image from a file into a PictureBox. The user may want to
move or delete the file that is being shown. The corresponding event-
driven code for "delete this picture" uses:
My.Computer.Fil eSystem.DeleteF ile(sPath)
The exception which is thrown tells me that the system cannot access
the file as it's "being used by another process". What other process?
(There is no multithreading in the app.) Presumably this means that
you can't do anything with a jpg image file while it's being displayed
in a PictureBox (whereas you could with VB6/W98). Annoying, but I
decided on a workaround that meant blanking out the PictureBox before
attempting to delete the file. I've experimented with several methods,
including loading a new image from a different (dummy) jpg file,
setting the Image property to a bitmap created on the fly, or just
doing this before the delete:
frmMainForm.pic Preview.Image.D ispose()
Still no luck - or rather, sometimes the deletion takes place without
problems, but most of the time it throws an exception, and if you loop
around and try again and again for a minute or two, usually the
exceptions just keep on coming. Still more mysteriously, tests suggest
that the system finally frees up the image file for deletion after a
few seconds in some cases (counting from where the PictureBox is
loaded with another image), or after a few minutes in others.
Can anyone figure out what's going on?
(I know that in theory you could dispense with the PictureBox
completely and just display the image using GDI+ graphics methods on
the form surface, but there are various reasons why implementing such
a solution would be hugely time-consuming for this app.)
On Apr 20, 11:46*pm, "Cor Ligthert[MVP]" <notmyfirstn... @planet.nl>
wrote:
Gerard,
What is *hugely time-consuming with drawing an Image on the surface, I am
not aware of the fact that after the scene is another method used for
drawing on the picturebox background surface.
Beside that does this simple code work for me.
PictureBox1.Loa d("d:\test.jpg" )
IO.File.Delete( "d:\test.jp g")
Something similar worked for me, too, until I tested in XP/Vista,
where the trouble started. Oddly, the exception is only thrown
sometimes, as I said.
I searched this newsgroup and eventually came across someone who had
the same problem. He was told to clone the image and then discard it.
Currently I'm testing the following (a variant of what was suggested):
Public Sub LoadImageClone( ByVal sPath As String, ByVal picPicBox
As PictureBox)
Dim bmpClone As Bitmap 'the clone to be loaded to a PictureBox
Dim bmpOriginal As New Bitmap(sPath) 'original file's bitmap,
original size
bmpClone = New Bitmap(bmpOrigi nal.Width, bmpOriginal.Hei ght)
'create clone, initially empty, same size
Dim gr As Graphics = Graphics.FromIm age(bmpClone) 'get object
representing clone's currently empty drawing surface
gr.DrawImage(bm pOriginal, 0, 0) 'copy original image onto this
surface
gr.Dispose()
bmpOriginal.Dis pose()
picPicBox.Image = bmpClone 'assign the clone to picture box
End Sub
It seems to work around 90% of the time, but there are occasional
sizing problems. I'll post the fix if I can figure it out. Thanks for
replying.
>
Cor
<gerardianle... @yahoo.comschre ef in berichtnews:93* *************** *************** ***@m36g2000hse .googlegroups.c om...
Any help appreciated.
(VB.NET under XP and Vista, SP1 installed)
My code, inherited from a VB6 version of an app that ran under W98,
loads an image from a file into a PictureBox. The user may want to
move or delete the file that is being shown. The corresponding event-
driven code for "delete this picture" uses:
* * * *My.Computer.Fi leSystem.Delete File(sPath)
The exception which is thrown tells me that the system cannot access
the file as it's "being used by another process". What other process?
(There is no multithreading in the app.) Presumably this means that
you can't do anything with a jpg image file while it's being displayed
in a PictureBox (whereas you could with VB6/W98). Annoying, but I
decided on a workaround that meant blanking out the PictureBox before
attempting to delete the file. I've experimented with several methods,
including loading a new image from a different (dummy) jpg file,
setting the Image property to a bitmap created on the fly, or just
doing this before the delete:
* * * *frmMainForm.pi cPreview.Image. Dispose()
Still no luck - or rather, sometimes the deletion takes place without
problems, but most of the time it throws an exception, and if you loop
around and try again and again for a minute or two, usually the
exceptions just keep on coming. Still more mysteriously, tests suggest
that the system finally frees up the image file for deletion after a
few seconds in some cases (counting from where the PictureBox is
loaded with another image), or after a few minutes in others.
Can anyone figure out what's going on?
(I know that in theory you could dispense with the PictureBox
completely and just display the image using GDI+ graphics methods on
the form surface, but there are various reasons why implementing such
a solution would be hugely time-consuming for this app.)- Hide quoted text -
- Show quoted text -
For the sake of anyone who might be looking for an answer, here's the
latest fix. The routine below is used to load a clone of the original
image into the picture box. Once this is done, the original image file
can be moved, deleted, or whatever. (I have a variant of the following
for thumbnail images, using ScaleTransform, which seems to work fine
too).
Public Sub LoadImageClone( ByVal sPath As String, ByVal picPicBox
As PictureBox)
Dim bmpClone As Bitmap 'the clone to be loaded to a PictureBox
Dim bmpOriginal As System.Drawing. Image =
System.Drawing. Image.FromFile( sPath) 'original file's bitmap, original
size
bmpClone = New Bitmap(bmpOrigi nal.Width, bmpOriginal.Hei ght)
'create clone, initially empty, same size
Dim gr As Graphics = Graphics.FromIm age(bmpClone) 'get object
representing clone's currently empty drawing surface
gr.SmoothingMod e = Drawing2D.Smoot hingMode.None
gr.Interpolatio nMode =
Drawing2D.Inter polationMode.Ne arestNeighbor
gr.PixelOffsetM ode = Drawing2D.Pixel OffsetMode.High Speed
gr.DrawImage(bm pOriginal, 0, 0, bmpOriginal.Wid th,
bmpOriginal.Hei ght) 'copy original image onto this surface
gr.Dispose()
bmpOriginal.Dis pose()
picPicBox.Image = bmpClone 'assign the clone to picture box
End Sub
Thanks for sharing, works for me.
<ge************ @yahoo.comwrote in message
news:4b******** *************** ***********@i36 g2000prf.google groups.com...
For the sake of anyone who might be looking for an answer, here's the
latest fix. The routine below is used to load a clone of the original
image into the picture box. Once this is done, the original image file
can be moved, deleted, or whatever. (I have a variant of the following
for thumbnail images, using ScaleTransform, which seems to work fine
too).
Public Sub LoadImageClone( ByVal sPath As String, ByVal picPicBox
As PictureBox)
Dim bmpClone As Bitmap 'the clone to be loaded to a PictureBox
Dim bmpOriginal As System.Drawing. Image =
System.Drawing. Image.FromFile( sPath) 'original file's bitmap, original
size
bmpClone = New Bitmap(bmpOrigi nal.Width, bmpOriginal.Hei ght)
'create clone, initially empty, same size
Dim gr As Graphics = Graphics.FromIm age(bmpClone) 'get object
representing clone's currently empty drawing surface
gr.SmoothingMod e = Drawing2D.Smoot hingMode.None
gr.Interpolatio nMode =
Drawing2D.Inter polationMode.Ne arestNeighbor
gr.PixelOffsetM ode = Drawing2D.Pixel OffsetMode.High Speed
gr.DrawImage(bm pOriginal, 0, 0, bmpOriginal.Wid th,
bmpOriginal.Hei ght) 'copy original image onto this surface
gr.Dispose()
bmpOriginal.Dis pose()
picPicBox.Image = bmpClone 'assign the clone to picture box
End Sub
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Christopher Benson-Manica |
last post by:
Is the following code legal, moral, and advisable?
#include <iostream>
class A {
private:
int a;
public:
A() : a(42) {}
|
by: Saso Zagoranski |
last post by:
Hi!
Here is what I'm trying to do:
I have created a UserControl named PictureView. It holds all the images
in one directory in the Bitmap images variable.
The selected image is displayed in the PictureBox control.
Here is how it works.
|
by: Ing. Rajesh Kumar |
last post by:
I am loading an XML File and validating that against an XSD file. Sometimes
when there is an error in the XML file, system locks the file and I am not
able to change the content of the file. When saving, It says that the file
may have been "locked by another application". Now i cannot fix the error
because i cannot save the changes. Probably the file get locks by
aspnet_wp.exe. How can I fix this ? I tried to load the file as readonly but...
|
by: lgbjr |
last post by:
Hello All,
I have a picturebox on a VB.NET form. I use an OpenfileDialog to select an
image for the picturebox (pb.image=image.fromfile(Openfiledialog.fileame)).
Once the image is loaded, I want to delete the file using
file.delete(OpenfileDialog.filename). however, this is throwing an exception
saying that the file is in use by another application.
After I load the image, what do I have to do to release the file so I can
delete it?
|
by: Jos Roijakkers |
last post by:
At some point in my application I load an image into a picturebox with the
code:
pbGraphic.Image = Image.FromFile("picture.jpg")
Later on in the program I want to rename the file using the code:
pbGraphic.Image = Nothing
My.Computer.FileSystem.RenameFile("picture.jpg","newname.jpg")
| |
by: Samuel R. Neff |
last post by:
When is it appropriate to use "volatile" keyword? The docs simply
state:
"
The volatile modifier is usually used for a field that is accessed by
multiple threads without using the lock Statement (C# Reference)
statement to serialize access.
"
But when is it better to use "volatile" instead of "lock" ?
|
by: Dave |
last post by:
I have a global.asax file with Application_Start defined and create some
static data there and in another module used in the asp.net application and
I realize that static data is shared amongst child apps of an IIS
application and can be used by multiple users during the application life
cycle and for multiple page loads for the same or different page under a
root application.
What I don't understand and need to know is whether that...
|
by: fniles |
last post by:
One of our application uses VB6 and Access97 database. Another application
uses VB.NET 2005.
This morning for about 15 seconds when the application tries to read either
a query or a table from the database, in in both VB6 and VB.NET
applications, I got the error "The Microsoft Jet database engine cannot find
the input table or query 'myTable'. Make sure it exists and that its name
is spelled correctly." Also, I got the error "The...
|
by: flea2k |
last post by:
I am trying to run this select statment against my DB2 database and it
is throwing the following error, is there a setting in my db2 database
to allow for this call "USE AND KEEP UPDATE LOCKS"?
SELECT * FROM user.tableA WHERE FIRST_NAME ='Billy' WITH RS USE AND
KEEP UPDATE LOCKS
SQL0104N An unexpected token "USE AND KEEP UPDATE LOCKS" was
found following "Billy' WITH RS". Expected tokens may
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
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();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| | |