从Windows.Media.DrawingImage转换为Windows.Media.Imaging.BitMapImage或Windows.Media.ImageSource [英] Converting from Windows.Media.DrawingImage to Windows.Media.Imaging.BitMapImage or Windows.Media.ImageSource

查看:153
本文介绍了从Windows.Media.DrawingImage转换为Windows.Media.Imaging.BitMapImage或Windows.Media.ImageSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从wpf接收到Windows.Media.DrawingImage类型的输入时遇到了一些麻烦,我需要将其转换为windows.media.ImageSource或windows.media.BitmapImage,以使我能够将它们转换为System.drawing.bitmap或System.drawing.image.

我已经在网上进行了广泛搜索,但是找不到答案.如果有人帮助我,我将非常感激

谢谢!

Am having some trouble that i''m recieving an input from wpf that is of type Windows.Media.DrawingImage and I need to convert it to either windows.media.ImageSource or to windows.media.BitmapImage inorder for me to convert those into System.drawing.bitmap or System.drawing.image.

I have already searched extensively online, but could not find an answer. I would be very graeful if someone were to help me out

thank you!

推荐答案

有一种非常残酷的方法:使用一个库向MemoryStream写一个位图,然后使用另一个库读取它;此方法可双向使用.

如果您需要从System.Drawing转到System.Windows.Media,则解决方法是使用System.Windows.Interop.Imaging
-SA
There is one pretty brutal way of doing it: write a bitmap to MemoryStream using one library and read it using another one; this method works in both directions.

If you needed to go from System.Drawing to System.Windows.Media, the solution would be in using System.Windows.Interop.Imaging, http://msdn.microsoft.com/en-us/library/system.windows.interop.imaging.aspx[^].

Unfortunately, you need to do your conversion in the opposite direction, so I don''t know other way then using the MemoryStream. Now, the code sample is already available on the page referenced by Abhinav, you simply did not recognize it. Go lower, find the sample code by the keyword "MemoryStream" and invert the direction of conversion.

—SA


尝试进行讨论

这篇关于从Windows.Media.DrawingImage转换为Windows.Media.Imaging.BitMapImage或Windows.Media.ImageSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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