从Windows.Media.DrawingImage转换为Windows.Media.Imaging.BitMapImage或Windows.Media.ImageSource [英] Converting from Windows.Media.DrawingImage to Windows.Media.Imaging.BitMapImage or 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
, ^ ].
不幸的是,您需要以相反的方向进行转换,因此我不知道使用MemoryStream
以外的其他方法.现在,Abhinav引用的页面上已经提供了代码示例,您根本无法识别它.往下走,通过关键字"MemoryStream"找到示例代码,然后反转转换方向.
-SA
There is one pretty brutal way of doing it: write a bitmap toMemoryStream
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 usingSystem.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 theMemoryStream
. 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屋!