Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,784 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am trying to convert a BitmapImage to a Byte() with the following code:
Dim ic As New ImageConverter
Dim bts() As Byte = DirectCast(ic.ConvertTo(clsImage, GetType(Byte())), Byte())
The error message I get is:
> Unable to cast object of type 'System.Windows.Media.Imaging.BitmapImage' to type 'System.Drawing.Image'.
The code does NOT attempt to convert the BitmapImage to another image so I don't how to fix this problem.
Hi, System.Drawing.ImageConverter converts objects from System.Drawing Namespace. Objects from namespace System.Windows.Media (PresentationCore.dll) like BitmapImage must be converted explicitly. Get byte array you can use this code:
Dim ms = TryCast(clsImage.StreamSource, MemoryStream)
Dim bts As Byte() = ms.ToArray