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