Greetings, such a question:

FileStream some_stream = File.OpenRead("путь и название файла"); 

File.OpenRead requires the path and name of the file to be downloaded. How to get it if I want to upload an image via FTP, which I currently have in my picturebox? That is, physically I have it only in winforms, not saved anymore.

  • "Upload image via ftp inserted in PictureBox?" What is it like? - AlexeyM

1 answer 1

I understand that the author of the question has not been on the site for a long time, and the question is a bit strange, but he has a rationale and a solution, I hope it will be useful to someone.

To begin, I will answer the question from the comment:

"Upload image via ftp inserted in PictureBox?" What is it like?

PictureBox has a property - ImageLocation , which allows you to specify the path or URL of the displayed image. You do not need to specify a value in the Image property, because it will be obtained automatically. Of course, if the address is correct and the image is available.

Therefore, there is not any mysticism here, it’s quite possible to get the address of the image in any available way, at least programmatically, even with copy-paste and get the picture in the PictureBox without having the actual picture file.

Now it's the author’s turn:

How to save the image obtained in this way

Since the image is read directly from the source, there is, of course, no file, just every time the form is loaded, the image is read from the specified address and an object of the Image class is formed, which is accessible through the PictureBox property of the same name.

To save, you need to refer to this object and use the Save method. At the same time, it is possible to specify the format of the saved file, and this actually allows the conversion of image formats received from the network into the desired format.

Well, a demo, where do without it:

 public class PictureForm : Form { public PictureForm() { PictureBox demoPictureBox = new PictureBox(); demoPictureBox.Parent = this; demoPictureBox.Dock = DockStyle.Fill; demoPictureBox.ImageLocation = "http://i.stack.imgur.com/SuN8J.png"; demoPictureBox.Click += (sender, e) => (sender as PictureBox).Image.Save("h:\\test.gif", ImageFormat.Gif); } } 

As you can see, the Image property is not used to set the image, but is used only for saving by clicking the mouse on the PictureBox . The original image in .png format will be saved to the test.gif file in .gif format.