|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Image Resource - not releasedI am loading a image into a picture box using this line of code
_objPic.Image = System.Drawing.Image.FromFile(_fileName) The picture box is then displayed on a form. The file in _fileName is a temperary file. After the form is closed down, I go back into the form and try and delete the tempary file used in the previous display. the application errors with cant delete rescource as it is used by another process. On closing the first form I call the dispose method. Nothing works until I close the application and start the process again. any ideas -- Life in the sun Hi,
Thank you posting! I am afraid this is a known issue. When you use the FromFile method to load a PictureBox control with a picture file at run time, the Visual Studio .NET Integrated Development Environment (IDE) maintains a lock on the file. To work around this problem, You need to avoid to use the FromFile method to load picture file to a PictureBox control directly. The alternative workarounds could be one of the following: 1. Use the FileStream object to load picture file insteadly: // Make sure that you have added the System.IO namespace. using System.IO; // Specify a valid picture file path on your computer. FileStream fs; fs = new FileStream("C:\\WINNT\\Web\\Wallpaper\\Fly Away.jpg", FileMode.Open, FileAccess.Read); pictureBox1.Image = System.Drawing.Image.FromStream(fs); fs.Close(); 2. Use the Bitmap( x, y, pixelformat ) constructor to create a 32bpp Bitmap, then Graphics.FromImage(), then draw your original Image on the new one and Dispose() the Graphics. Please refer to the following newsgroup thread: http://groups.google.com/group/microsoft.public.dotnet.framework.drawing/bro wse_frm/thread/9f22e459fcace234/0341a75ce3662728?lnk=st&q=System.Drawing.Ima ge.FromFile+file+lock&rnum=8&hl=en#0341a75ce3662728 3. Use the Img.GetTumbnailImage to load image to the PictureBox control, please refer to the following newsgroup thread for sample code: http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_f rm/thread/f3d2227be4476c01/f0103a542b89a1cb?lnk=st&q=System.Drawing.Image.Fr omFile+file+lock&rnum=4&hl=en#f0103a542b89a1cb I hope the above information helps, if you have any questions or concerns, please do not hesitate to let me know. I am standing by to help you. Thanks! Best regards, Gary Chang Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. Gary,
Number one works great thanks -- Show quoteHide quoteLife in the sun ""Gary Chang[MSFT]"" wrote: > Hi, > > Thank you posting! > > I am afraid this is a known issue. When you use the FromFile method to load > a PictureBox control with a picture file at run time, the Visual Studio > .NET Integrated Development Environment (IDE) maintains a lock on the file. > > To work around this problem, You need to avoid to use the FromFile method > to load picture file to a PictureBox control directly. The alternative > workarounds could be one of the following: > > 1. Use the FileStream object to load picture file insteadly: > // Make sure that you have added the System.IO namespace. > using System.IO; > > // Specify a valid picture file path on your computer. > FileStream fs; > fs = new FileStream("C:\\WINNT\\Web\\Wallpaper\\Fly Away.jpg", > FileMode.Open, FileAccess.Read); > pictureBox1.Image = System.Drawing.Image.FromStream(fs); > fs.Close(); > > 2. Use the Bitmap( x, y, pixelformat ) constructor to create a 32bpp > Bitmap, then Graphics.FromImage(), then draw your original Image on the new > one and Dispose() the Graphics. Please refer to the following newsgroup > thread: > http://groups.google.com/group/microsoft.public.dotnet.framework.drawing/bro > wse_frm/thread/9f22e459fcace234/0341a75ce3662728?lnk=st&q=System.Drawing.Ima > ge.FromFile+file+lock&rnum=8&hl=en#0341a75ce3662728 > > 3. Use the Img.GetTumbnailImage to load image to the PictureBox control, > please refer to the following newsgroup thread for sample code: > http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_f > rm/thread/f3d2227be4476c01/f0103a542b89a1cb?lnk=st&q=System.Drawing.Image.Fr > omFile+file+lock&rnum=4&hl=en#f0103a542b89a1cb > > I hope the above information helps, if you have any questions or concerns, > please do not hesitate to let me know. I am standing by to help you. > > Thanks! > > Best regards, > > Gary Chang > Microsoft Online Community Support > ================================================== > When responding to posts, please "Reply to Group" via your newsreader so > that others may learn and benefit from your issue. > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. > > > I am glad to know it works. :)
Have a nice weekend! Best regards, Gary Chang Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. ""Gary Chang[MSFT]"" <v-gar***@online.microsoft.com> schrieb:
> 1. Use the FileStream object to load picture file insteadly: Note that the stream the image object is based on must not be closed as long > // Make sure that you have added the System.IO namespace. > using System.IO; > > // Specify a valid picture file path on your computer. > FileStream fs; > fs = new FileStream("C:\\WINNT\\Web\\Wallpaper\\Fly Away.jpg", > FileMode.Open, FileAccess.Read); > pictureBox1.Image = System.Drawing.Image.FromStream(fs); > fs.Close(); as the image object is used! Two solutions can be found here: <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/> Nice Tip...I'll use it.
-- Show quoteHide quoteDennis in Houston "Herfried K. Wagner [MVP]" wrote: > ""Gary Chang[MSFT]"" <v-gar***@online.microsoft.com> schrieb: > > 1. Use the FileStream object to load picture file insteadly: > > // Make sure that you have added the System.IO namespace. > > using System.IO; > > > > // Specify a valid picture file path on your computer. > > FileStream fs; > > fs = new FileStream("C:\\WINNT\\Web\\Wallpaper\\Fly Away.jpg", > > FileMode.Open, FileAccess.Read); > > pictureBox1.Image = System.Drawing.Image.FromStream(fs); > > fs.Close(); > > Note that the stream the image object is based on must not be closed as long > as the image object is used! Two solutions can be found here: > > <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/> > >
strange behavior , has someone an explanation for this ??
Windows Forms and Console Application [VB2005EE] accessing control-specific functions via form's ActiveControl Visual C to Visual Basic Converstion Help... Data type conversion question DataViews with DataSets 'Incremental Search' of data base or "Wheres the 'Seek' method Reading and Writing Text Files .Net Mail only goes to one Problem with MoveFile command in ASP page |
|||||||||||||||||||||||