How to avoid blocking the file that you upload in PictureBox using Image.FromFile?

1

I want to upload an image but when I try to replace the file it returns that the file is being used. How can I avoid taking the file directly, leaving me the possibility of being able to replace it?

Usage:

PictureBox1.Image = Image.FromFile("D:\images\out.png")
    
asked by Fabrizio Piminchumo 29.11.2017 в 22:49
source

3 answers

1

Instead of using Image.FromFile , you can use Image.FromStream and pass the bytes of the file using File.ReadAllBytes .

Example:

PictureBox1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes("D:\images\out.png")))
    
answered by 29.11.2017 / 23:02
source
0

You CAN NOT , this is a restriction added by the framework reading system, I recommend if you want to use / modify the file, create a temporary copy, modify it and visualize it. Otherwise you can never do both at the same time.

    
answered by 29.11.2017 в 22:53
-1

The following trick worked for me:

picturebox.image=new Bitmap(Image.FromFile(ruta));

He gave me the solution to the same problem.

    
answered by 15.03.2018 в 05:47