Extract image from wpf image control and save it to a png file on my local PCc# -


i have image control in wpf c#.

<image x:name="icon01" mousedown="icon_mousedown" cursor="hand" source="favicon\01.png" height="48" width="48" margin="10"/> 

how can save image (favicon\01.png) file on pc? use c# .net 4.0.

use icon01.source(imagesource) create filestream via pngbitmapencoder, here example using savefiledialog

 private void icon_mousedown(object sender, mousebuttoneventargs e)     {         try         {             var savefiledialog = new savefiledialog()             {                 filter = "image files (*.bmp, *.png, *.jpg)|*.bmp;*.png;*.jpg"             };             if (savefiledialog.showdialog() == true)             {                  var encoder = new pngbitmapencoder();                 encoder.frames.add(bitmapframe.create((bitmapsource)icon01.source));                 using (filestream stream = new filestream(savefiledialog.filename, filemode.create))                     encoder.save(stream);             }          }         catch (exception exception)         {             messagebox.show(exception.message);         }     } 

and xaml same :

 <grid>      <image x:name="icon01" mousedown="icon_mousedown" cursor="hand" source="favicon\01.png" height="48" width="48" margin="10"/>  </grid> 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -