的BitmapSource到的BitmapImageBitmapSource、BitmapImage

由网友(霸气但不失妩媚的女子)分享简介:我需要解析的内容Clipboard.GetImage()(A 的BitmapSource )到的BitmapImage 。没有人知道如何才能做到这一点?I need to parse the content of Clipboard.GetImage() (a BitmapSource) to a BitmapIm...

我需要解析的内容Clipboard.GetImage()(A 的BitmapSource )到的BitmapImage 。 没有人知道如何才能做到这一点?

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

推荐答案

我发现一个很干净的解决方案,它的工作原理:

I've found a quite 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);

        bImg.BeginInit();
        bImg.StreamSource = new MemoryStream(memoryStream.ToArray());
        bImg.EndInit();

        memoryStream.Close();

        return bImg;
阅读全文

相关推荐

最新文章