By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,969 Members | 2,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,969 IT Pros & Developers. It's quick & easy.

image file locked after use

P: n/a

I am creating a website updater program. Currently working on the image

replacement module here.

For some reason, after an image (say /images/1.jpg) has been
used/opened in the application. I cannot later overwrite it (during the

application), even after i have closed it.
"My.Computer.FileSystem.CopyFile(OpenFileDialog1.F ileName,
"\images\posters\" & Me.imagenum & ".jpg", True)"
The process cannot access the file 'C:...\images\posters\1.jpg' because

it is being used by another process.
Is there a way to unload this image so that I can overwrite it? As soon

as my application quits, the lock is removed. I can tell that my
program is locking the file, but the image is not being displayed or
used at that time!!
Form3.PictureBox1.Image = System.Drawing.Bitmap.FromFile(imgpath)

is how it is being loaded.
is there a way to unload that? / free up the resource for
editing/deletion.

another way to do what i'm trying?


please help,
Thanks,
Ted

Mar 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Set the image to Nothing:

Form3.PictureBox1.Image = Nothing

james

<th******@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...

I am creating a website updater program. Currently working on the image

replacement module here.

For some reason, after an image (say /images/1.jpg) has been
used/opened in the application. I cannot later overwrite it (during the

application), even after i have closed it.
"My.Computer.FileSystem.CopyFile(OpenFileDialog1.F ileName,
"\images\posters\" & Me.imagenum & ".jpg", True)"
The process cannot access the file 'C:...\images\posters\1.jpg' because

it is being used by another process.
Is there a way to unload this image so that I can overwrite it? As soon

as my application quits, the lock is removed. I can tell that my
program is locking the file, but the image is not being displayed or
used at that time!!
Form3.PictureBox1.Image = System.Drawing.Bitmap.FromFile(imgpath)

is how it is being loaded.
is there a way to unload that? / free up the resource for
editing/deletion.

another way to do what i'm trying?


please help,
Thanks,
Ted

Mar 21 '06 #2

P: n/a
Hello, Ted,

I recently ran into a similar problem. I learned that there was a
"feature" of GDI+ that keeps the source file locked after the image is
loaded.

See "http://support.microsoft.com/?id=814675" for details and work-arounds.

Cheers,
Randy
th******@gmail.com wrote:
I am creating a website updater program. Currently working on the image

replacement module here.

For some reason, after an image (say /images/1.jpg) has been
used/opened in the application. I cannot later overwrite it (during the

application), even after i have closed it.
"My.Computer.FileSystem.CopyFile(OpenFileDialog1.F ileName,
"\images\posters\" & Me.imagenum & ".jpg", True)"
The process cannot access the file 'C:...\images\posters\1.jpg' because

it is being used by another process.
Is there a way to unload this image so that I can overwrite it? As soon

as my application quits, the lock is removed. I can tell that my
program is locking the file, but the image is not being displayed or
used at that time!!
Form3.PictureBox1.Image = System.Drawing.Bitmap.FromFile(imgpath)

is how it is being loaded.
is there a way to unload that? / free up the resource for
editing/deletion.

another way to do what i'm trying?


please help,
Thanks,
Ted

Mar 21 '06 #3

P: n/a
<th******@gmail.com> schrieb:
For some reason, after an image (say /images/1.jpg) has been
used/opened in the application. I cannot later overwrite it (during the
application), even after i have closed it.


Check out the code samples at
<URL:http://dotnet.mvps.org/dotnet/code/graphics/#ImageNoLock>.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 21 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.