Home All Groups Group Topic Archive Search About

image file locked after use

Author
20 Mar 2006 11:42 PM
thebhone
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.FileName,
"\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

Author
21 Mar 2006 1:29 AM
james
Set the image to Nothing:

Form3.PictureBox1.Image = Nothing

james

<thebh***@gmail.com> wrote in message
Show quoteHide quote
news:1142898126.594243.242770@e56g2000cwe.googlegroups.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.FileName,
> "\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
>
Author
21 Mar 2006 9:18 AM
R. MacDonald
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


thebh***@gmail.com wrote:

Show quoteHide quote
> 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.FileName,
> "\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
>
Author
21 Mar 2006 9:27 AM
Herfried K. Wagner [MVP]
<thebh***@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/>