Click here to Skip to main content
15,888,111 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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!
Posted
Comments
Sergey Alexandrovich Kryukov 7-Aug-11 3:51am    
This is really a problem, but solvable. Calm down, get some catnip :-) I voted 5 for this interesting question.
--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
 
Share this answer
 
v2
Comments
Abhinav S 7-Aug-11 3:47am    
Good solution. My 5.
Sergey Alexandrovich Kryukov 7-Aug-11 3:53am    
Thank you, Abhinav.
--SA
Try going through the discussion here[^].
 
Share this answer
 
Comments
nervous_cat 4-Aug-11 5:29am    
Interesting, but the link u sent was more dealing with bitmaps and images under the System.Drawing, what I need is to convert components under Windows.Media. although it poses somethign interesting, as to change the drawingimage to a byte array and then tranfer that to a bitmapimage.
thanks!
Sergey Alexandrovich Kryukov 7-Aug-11 3:49am    
You are right! See my solution -- you will find a right explanation. Also, I tested this method before, it will work, I'll guarantee it :-)
--SA
Sergey Alexandrovich Kryukov 7-Aug-11 3:48am    
Abhinav, I have some information for you. First, OP is right: what you advise works in the opposite direction. Also, if one needs to go the opposite direction, the best method is not mentioned in this discussion; this is using System.Windows.Interop.Imaging.

Now, please see my solution. I actually found that the solution is available in one of the posts of the page you referenced -- the MemoryStream, only it needs to be modified. If you knew that, you should have explained it.

So, I credited your answer and voted 4, explained everything in my solution, please see.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900