473,413 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Unlocking file when assigned to PictureBox

Hello,

Say I write a picture file to: 'c:\test.jpg'

Then I assign this picture to a picturebox
PbFoto.Image = Image.Fromfile("c:\test.jpg")

Next I want the overrwrite the file test.jpg with another picture.

When running, he says the file is in use when I want to overwrite it.
(if not assignd to the picture box, I can overwritte as many as I want)

I've tried 'PbFoto.Image = Nothing', but that didn't help also.

Anyone an idea how to free the file?
Nov 21 '05 #1
2 3721
On Wed, 22 Sep 2004 13:25:03 +0200, Mark wrote:
Hello,

Say I write a picture file to: 'c:\test.jpg'

Then I assign this picture to a picturebox
PbFoto.Image = Image.Fromfile("c:\test.jpg")

Next I want the overrwrite the file test.jpg with another picture.

When running, he says the file is in use when I want to overwrite it.
(if not assignd to the picture box, I can overwritte as many as I want)

I've tried 'PbFoto.Image = Nothing', but that didn't help also.

Anyone an idea how to free the file?


Look elsewhere in these groups for more information, but I believe the
solution offered is to use the FromStream method instead of using the
Image.FromFile method. When using FromStream, the file is not locked.

Perhaps this code can help:

Imports System.IO
Imports System.Drawing

Dim fs As System.IO.FileStream
fs = New FileStream("C:\test.jpg", FileMode.Open, FileAccess.Read)
PictureBox1.Image = Image.FromStream(fs)
fs.Close()
--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #2

for memory optimization reasons GDI+ locks the file.

' --------------------------------------
' 1. Final Version:
'! myP.Image = Image.FromFile(src)
' --------------------------------------
' 2. Edit Version:
' based on MSDN:
' Image File Is Locked When You Set the PictureBox Image
' Property to a File
' http://support.microsoft.com/default...id=kb;;Q309482
Dim fs As System.IO.FileStream
fs = New System.IO.FileStream(src, IO.FileMode.Open, IO.FileAccess.Read)
'TODO: Add exeption: 'Directory not found'
'TODO: Add exeption: 'System.IO.FileNotFoundException'
myP.Image = System.Drawing.Image.FromStream(fs)
fs.Close()
' --------------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bill N. | last post by:
Using VB .Net 2003 Standard Edition. This simple form has a "File in Use" problem while the executable is running. Created this simple program to make sure that I hadn't done something in my...
7
by: user | last post by:
Hello I tried: pictureBox1.Image.Save("file.sav"); compiled, but when i run i receive errors: Additional information: Object reference not set to an instance of an object. Why ?
12
by: yaya via DotNetMonster.com | last post by:
Hi, I have a picture box with circles and rectangles, and I wana save all the images into a jpg file, i tried pictureBox1.Image.Save(@"c:\1.jpg"); but I got and error...
1
by: Just Me | last post by:
I've been disposing whenever I create a bitmap or graphics object. Recently I developed a bug which turned out to be as follows: bmp=new Bitmap(... picBox.Image = bmp .. .. bmp.dispose...
2
by: Mattbooty | last post by:
Hello, Not sure if anyone else has seen this bug, but I have a form where the entire form is covered with a picturebox. The picturebox has a mouseup event. I also have an open file dialog for...
0
by: prl | last post by:
hey there! I have a pictureBox in my application with a chart drawn by me (line by line..). What I want to do now is to save that chart in a image file (.bmp). Is that possible? And how can I...
3
by: NaeiKinDus | last post by:
Hello, i'm trying to program a thread that would be locked (by a mutex) and that would only be unlocked once that a function (generating data) is done. The purpose is to generate data, and unlock...
0
by: Johnny Jörgensen | last post by:
I'm currently doing an application in VB.NET 2005 where I need the possiblity to perform certain file tasks: 1) I've got a HTML page open in a WebBrowser control. I want the user to be...
4
by: gerardianlewis | last post by:
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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,...
0
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...

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.