BitmapSource to BitmapImage BitmapSource to BitmapImage wpf wpf

BitmapSource to BitmapImage


I've found a clean solution that works:

BitmapSource bitmapSource = Clipboard.GetImage();JpegBitmapEncoder encoder = new JpegBitmapEncoder();MemoryStream memoryStream = new MemoryStream();BitmapImage bImg = new BitmapImage();encoder.Frames.Add(BitmapFrame.Create(bitmapSource));encoder.Save(memoryStream);memoryStream.Position = 0;bImg.BeginInit();bImg.StreamSource = memoryStream;bImg.EndInit();memoryStream.Close();return bImg;


using System.IO; // namespace for  using MemoryStreamprivate static byte[] ReadImageMemory(){    BitmapSource bitmapSource = BitmapConversion.ToBitmapSource(Clipboard.GetImage());    JpegBitmapEncoder encoder = new JpegBitmapEncoder();    MemoryStream memoryStream = new MemoryStream();    encoder.Frames.Add(BitmapFrame.Create(bitmapSource));    encoder.Save(memoryStream);    return memoryStream.GetBuffer();}// and calling by this example........byte[] buffer = ReadImageMemory();