I'm converting an old .NET Framework 4 WinForms application to .NET 5. In this case, the easiest way was to re-create the project, which mostly worked. However, I have a method to decode a JPG image from a memory stream:
// Look for JFIF header
MemoryStream memStream = new MemoryStream( rawData );
JpegBitmapDecoder decoder = new JpegBitmapDecoder( memStream,
BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default );
BitmapSource bmpSource = decoder.Frames[0];
Bitmap bitmap = new Bitmap( bmpSource.PixelWidth, bmpSource.PixelHeight,
PixelFormat.Format24bppRgb );
This fails because VS 2019 complains that "using System.Windows.Media.Imaging" causes an error, and JpegBitmapDecoder shows with a red squiggly. If I hover over JpegBitmapDecoder, I'm given the option for "using System.Windows.Media.Imaging; from PresentationCode".
However, choosing that causes VS 2019 to be stuck on "Execute Suggested Action", trying to add the using.
The project is targeted for .NET 5, and I've added the Microsoft.Windows.Compatibility NuGet package, so what am I doing wrong? Or, how to I access the JpegBitmapDecoder?
