的BitmapSource到的BitmapImage [英] BitmapSource to BitmapImage

查看:246
本文介绍了的BitmapSource到的BitmapImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要解析的内容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;

这篇关于的BitmapSource到的BitmapImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆