Is there any way to convert from a System.Windows.Media.Imaging.BitmapSource
to a System.Windows.Media.Visual
? I have an instance of a BitmapSource
but I'd like to convert it to a Visual
so I can take advantage of WPF vector graphics. I've seen lots of examples of going from Visual to bitmap but how can I go the other direction using C#?
var stream = new FileStream(
@"C:\Image.png", FileMode.Open, FileAccess.Read, FileShare.Read);
var decoder = new PngBitmapDecoder(
stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bitmapSource = decoder.Frames[0];
// Visual visual = bitmapSource.ToVisual(); <-- I'd like to do this