Mistake

There is an image in which the picture was previously loaded, you have to click on the button to copy this image into the images folder, which lies in the folder with the file (without opening the dialog box).
I have already tried many options, I can not achieve the result ...

If you know the option better, you can write it.

  • FirstImage my image
  • nametext field in which the name is entered

You need at least an example of copying a previously downloaded image.

Loading pictures:

 private void Donwnlimg_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.FileName = ""; // Default file name // dlg.DefaultExt = ".png"; // Default file extension dlg.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" + "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" + "Portable Network Graphic (*.png)|*.png"; // Filter files by extension // Show open file dialog box Nullable<bool> result = dlg.ShowDialog(); // Process open file dialog box results if (result == true) { // Open document Firstimage.Source = new BitmapImage(new Uri(dlg.FileName)); } } 

My attempts:

 private void vnecti(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); FileStream fs = new FileStream("images//" + nametext.Text + ".jpg", FileMode.CreateNew); string stroka = fs.Name; FileInfo f = new FileInfo(nametext.Text); f.CopyTo(stroka); } 
  • The user in the dialog box selects a picture - Frallen 5:46 pm
  • This is the problem, and it doesn’t work either. In the example code above, I tried to do this, but the image is not copied, it just creates a jpg file, it is empty - Frallen
  • one
  • And what have this image with an error? - EvgeniyZ pm

1 answer 1

  var encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create((BitmapSource)Firstimage.Source)); using (var stream = File.Create(@"images//"+nametext.Text+".png")) encoder.Save(stream); 
  • Images are saved in the images folder (there is my file)
  • The nametext.Text text entered there will be the name of my file.
  • Input files are converted to png