我需要将 Clipboard.GetImage()
的内容(一个 BitmapSource
)解析为一个 BitmapImage
。
有谁知道如何做到这一点?
最佳答案
我找到了一个干净的解决方案:
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;
关于c# - BitmapSource 到 BitmapImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5338253/