BitmapSource to BitmapImage

后端 未结 2 1875
小蘑菇
小蘑菇 2020-12-14 18:25

I need to parse the content of Clipboard.GetImage() (a BitmapSource) to a BitmapImage. Does anyone knows how can this be done?

2条回答
  •  北海茫月
    2020-12-14 18:46

    using System.IO; // namespace for  using MemoryStream
    
    private 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();
    

提交回复
热议问题