public BitmapSource ConvertToBitmapSource(Bitmap src, ImageFormat imageFormat)
{
try
{
MemoryStream ms = new MemoryStream();
src.Save(ms, imageFormat);
BitmapImage image = new BitmapImage();
image.BeginInit();
ms.Seek(0, SeekOrigin.Begin);
image.StreamSource = ms;
image.EndInit();
return image;
}
catch
{
// ignored
}
return null;
}