Pro_Zeck
Pro_Zeck

Reputation: 403

How to save an image to a file in WPF

I am new in wpf control and framework. I cant seem to save my images can you help me Below is my code

            SaveFileDialog sfd = new SaveFileDialog();
            sfd.FileName = System.IO.Path.GetFileNameWithoutExtension(newlist[currentPicture]);                              
            Nullable<bool> result = sfd.ShowDialog();
            if (result == true)
            {

                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(newlist[currentPicture]);
                bmp.Save(newlist[currentPicture]);
            }

Upvotes: 2

Views: 5496

Answers (1)

SLaks
SLaks

Reputation: 887195

For a System.Drawing.Bitmap, you need to pass the dialog's FileName property to the Save method.

EDIT: In WPF:

var encoder = new PngBitmapEncoder()
encoder.Frames.Add(BitmapFrame.Create(image));
using (var stream = dialog.OpenFile())
    encoder.Save(stream);

Upvotes: 3

Related Questions