Search code examples
c#bitmapbitmapsource

Get bitmapsource from a picturebox in C#


I have a picturebox called picture I want to get the image of this picturebox and save it as bitmapsource

BitmapSource myPic;
  myPic = picture.Image;

But i get this error :

Severity Code Description Project File Line Suppression State Error CS0029 Cannot implicitly convert type 'System.Drawing.Image' to 'System.Windows.Media.Imaging.BitmapSource'


Solution

  • You need to convert the System.Drawing.Image to a System.Drawing.Bitmap and next convert it to a BitmapSource.

    You can pick one of this solutions: fast converting Bitmap to BitmapSource wpf