1

Here this is my code

var stream = new MemoryStream();
await responseStream.CopyToAsync(stream);

stream.Position = 0;
var Result = stream;
byte[] bytes = stream.ToArray();
string Base64 = System.Convert.ToBase64String(bytes);

// get the size of the image
MemoryStream ms = new MemoryStream(bytes);
Image returnImage = Image.FromStream(ms);
Bitmap resizedImage = new(returnImage, new Size(310, 212));
                                              resizedImage.Save(stream, ImageFormat.Jpeg);

VisaItineraryResponse.Pax.ElementAt(paxindex)
                         .Docs.ElementAt(DocIndex).Base64String = Convert.ToString(resizedImage);

I got an exception while using this code

System.Exception: Failed
System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.
System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information.

Progman
  • 16,827
  • 6
  • 33
  • 48
Riya Jose
  • 11
  • 1
  • 2
    In short, you need to use a different API or library. I personally have used SixLabours.ImageSharp and was fairly satisfied with the results. – Sergey Kudriavtsev Dec 28 '22 at 09:34
  • If you want to use System.Drawing on non-windows platforms, you'll need this configuration https://stackoverflow.com/questions/70310747/net-6-system-drawing-common-runtime-switch – StefanFFM Dec 28 '22 at 13:55
  • @StefanFFM that doesn't work. It's only a stop-gap measure until you can migrate legacy code to other libraries. `System.Drawing` is a thin layer over GDI+, a Windows API and is really only meant to draw to the screen. It does offer some limited image manipulation support but that's it. To get it to work on Linux you'd have to emulate the entire GDI+ API, most of which is simply meaningless in web or console applications – Panagiotis Kanavos Dec 28 '22 at 16:01

1 Answers1

1

If you click on the provided link in the exception, it says

Because System.Drawing.Common was designed to be a thin wrapper over Windows technologies, its cross-platform implementation is subpar.

Recommended action

To use these APIs for cross-platform apps, migrate to one of the following libraries:

I have used skiasharp and would recommend it. I can't say how that compares to maui graphics.

BurnsBA
  • 4,347
  • 27
  • 39