473,400 Members | 2,163 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,400 software developers and data experts.

Problems with FileAccess and PcitoreBox

Hi

For viewing pictures I am using a pictures box... For making proper saving
of the pic, I must delete an existing pic-file and overwrite it with the
picture in the picturebox... Trying this I always get an exeption, that the
file is in use... This is my code...

'remarks
Imports System.IO
Imports System.Drawing
'

Dim mytempic as String= "X:\Photos\MyTempPic1.jpg"
If System.Io.File.Exists(mytempic) = False Then
Me.pboPicture.Image.Save(mytempPic)
Else
Dim tempPic As String = "X:\Photos\tmp.jpg"
Me.pboPicture.Image.Save(tempPic)
Me.pboPicture.Image = Image.FromFile(tempPic)
'The error occurs here, but I cleared the picturebox
File.Delete(mytemppic)
Me.pboPicture.Image.Save(mytempic)
'other way to load the picture
Me.pboPicture.ImageLocation = mytempic
Me.pboPicture.Load()
End If

end if
If anyone has an idea, please write... I tried everything and didn't get it
work...

Thanks alot

Nijazi Halimaji

--
Nijazi Halimaji
brain solutions
in**@brainsolutions.ch
www.brainsolutions.ch
Feb 6 '06 #1
2 1106
Hi I always load a temp copy of the original image in a picturebox if I'm
going to do some editing to a picture.
So I don't use Me.pboPicture.Image = Image.FromFile(tempPic), I hope my
sample below is clear enough to do the rest of the explanation

Dim myLoc As String = "c:\2.jpg"
Dim myBmp As Bitmap
Dim myNewBmp As Bitmap
Dim g As Graphics

myBmp = DirectCast(Bitmap.FromFile(myLoc), Bitmap)
myNewBmp = New Bitmap(myBmp.Width, myBmp.Height)
myNewBmp SetResolution(myBmp.HorizontalResolution, myBmp.VerticalResolution)

g = Graphics.FromImage(myNewBmp)
g.DrawImage(myBmp, New Rectangle(0, 0, myBmp.Width, myBmp.Height), 0, 0,
myBmp.Width, myBmp.Height, GraphicsUnit.Pixel)
g.DrawString("Peter Proost vb.net", Me.Font, Brushes.Black, 2, 2)

myBmp.Dispose()
g.Dispose()
PictureBox1.Image = myNewBmp

If System.IO.File.Exists(myLoc) Then
System.IO.File.Delete(myLoc)
End If

myNewBmp.Save(myLoc, Imaging.ImageFormat.Jpeg)
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"Halimaji Nijazi" <te**@hotmail.com> schreef in bericht
news:e0*************@TK2MSFTNGP12.phx.gbl...
Hi

For viewing pictures I am using a pictures box... For making proper saving
of the pic, I must delete an existing pic-file and overwrite it with the
picture in the picturebox... Trying this I always get an exeption, that the file is in use... This is my code...

'remarks
Imports System.IO
Imports System.Drawing
'

Dim mytempic as String= "X:\Photos\MyTempPic1.jpg"
If System.Io.File.Exists(mytempic) = False Then
Me.pboPicture.Image.Save(mytempPic)
Else
Dim tempPic As String = "X:\Photos\tmp.jpg"
Me.pboPicture.Image.Save(tempPic)
Me.pboPicture.Image = Image.FromFile(tempPic)
'The error occurs here, but I cleared the picturebox
File.Delete(mytemppic)
Me.pboPicture.Image.Save(mytempic)
'other way to load the picture
Me.pboPicture.ImageLocation = mytempic
Me.pboPicture.Load()
End If

end if
If anyone has an idea, please write... I tried everything and didn't get it work...

Thanks alot

Nijazi Halimaji

--
Nijazi Halimaji
brain solutions
in**@brainsolutions.ch
www.brainsolutions.ch

Feb 6 '06 #2
"Halimaji Nijazi" <te**@hotmail.com> schrieb:
For viewing pictures I am using a pictures box... For making proper saving
of the pic, I must delete an existing pic-file and overwrite it with the
picture in the picturebox... Trying this I always get an exeption, that
the file is in use...


Check out the two snippets 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/>

Feb 6 '06 #3

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

Similar topics

2
by: Suzanne | last post by:
Hi all, I'm attempting to save images (that are in jpeg format) to a database column of type image. I've read over the Microsoft Knowledge Base articles for this and I can get things working...
4
by: Shane Mergy | last post by:
i have a program that reads through an ini file and does stuff so far the only thing i am having trouble with is the writing to the ini file. if the section is alreadey there i want to do a search...
2
by: kj96 | last post by:
I have a intranet page that I want to use to open a certain file from a network location make changes to it and then write the changed file back to the same network location <my try at the code>...
1
by: Jim S | last post by:
I have an application where I have to make a tree of objects. To do this, I have my own node class. At certain points in the application, I need to save data. I am having a problem with the...
9
by: Alexandre | last post by:
Hey im serializing objects to files am i forgeting something it works great but once they are written i dont have access to deleting them or overwriting them.. my folder properties are everyone...
4
by: Erpman | last post by:
I am trying to access the data with in a wav file. I am testing with very small files in order to keep the code simple to start with. Basically, im writing the entire wav file to a byte using a...
1
by: chauc3r | last post by:
I'm having problems writing to a text file. Basically it refuses to write anything. The file is created. At the appropiate times it goes into the correct if statements (I have verified this...
0
by: neoret | last post by:
Hello. I have developed an application (an office addin).The application works fine with no error messages on my devoping machine (that machine is not connected to any domains). I have...
0
by: neoret | last post by:
Hello. I have developed an application (an office com addin).The application works fine with no error messages on my devoping machine (that machine is not connected to any domains). I have...
2
by: Andez | last post by:
I've wrote a windows service that performs simple functions within our application. To ensure safe running of the service - if it errors we want to know where when how - it logs to a text file - in...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
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
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...
0
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...
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.