Displaying an Image Without Locking its File

July 5, 2010 | By

http://zencio.com/?opt=Binary-Option-Trading-In-Nicaragua-Blog Binary Option Trading In Nicaragua Blog http://bmwcoop.com/?opt=Anterioara-Forex-Pre%C8%9Buri-Rom%C3%A2nia Anterioara Forex Prețuri România Forexexpo Fm Of Radio Forex Forex Trading и Тоҷикистон http://yseal.ca/?topic=Indicator-Binary-Option-Itm-Signal-Service-2016 Indicator Binary Option Itm Signal Service 2016 Indicator Binary Option Itm Signal Service 2016 Forex Trading и Тоҷикистон The best solution to this problem is to load the file as stream using the Image.FromStream function. The following code is an example of how to do this.

Filed in: WinForms | Tags: ,

Comments (4)

Links to this Post

  1. DotNetShoutout | July 21, 2010
  1. Luc Pattyn

    Hi,

    I am aware using Image.FromStream() seems to solve the file-locked problem, however the MSDN documentation (http://msdn.microsoft.com/en-us/library/93z9ee4x.aspx) clearly says the stream should remain open as long as the Image exists; I’m afraid that implies the file, while not locked, should remain accessible.

    To be absolutely safe, I think one should read the file into a MemoryStream, then use Image.FromStream() from there.

    Cheers.

  2. Luc thanks for the input. You’re right, the file should remain accessible, but in this case the buffer is the PictureBox control’s image property so you don’t need a MemoryStream object.

  3. John

    Once you close the stream, the image is no longer savable.