ststeiger / PdfSharpCore

Port of the PdfSharp library to .NET Core - largely removed GDI+ (only missing GetFontData - which can be replaced with freetype2)
Other
1.06k stars 235 forks source link

Create xImage object from MemoryStream doesn't work #348

Open Ervin304 opened 1 year ago

Ervin304 commented 1 year ago

I can't create an xImage object from the MemoryStream of a png image I get from Azure blob storage. I always get IvalidFormatException.

The problem are these lines (PdfSharpCore.Utils.ImageSharpImageSource.cs)

using (var stream = imageStream.Invoke()) { var image = Image.Load(stream, out IImageFormat imgFormat); return new ImageSharpImageSourceImpl(name, image, (int)quality, imgFormat is PngFormat); }

You should implement somethink like this:

using (var MemoryStream= imageStream.Invoke()) { var image = Image.Load(stream.ToArray(), out IImageFormat imgFormat); return new ImageSharpImageSourceImpl(name, image, (int)quality, imgFormat is PngFormat); }

redtalon616 commented 1 year ago

Error occurs when running the following code: MemoryStream strm = new MemoryStream(); img.Save(strm, System.Drawing.Imaging.ImageFormat.Png); strm.Position = 0;

            PdfSharpCore.Drawing.XImage pdfimage = PdfSharpCore.Drawing.XImage.FromStream(() => strm);

Error details: System.MissingMethodException HResult=0x80131513 Message=Method not found: 'SixLabors.ImageSharp.Image1<!!0> SixLabors.ImageSharp.Image.Load(System.IO.Stream, SixLabors.ImageSharp.Formats.IImageFormat ByRef)'. Source=PdfSharpCore StackTrace: at PdfSharpCore.Utils.ImageSharpImageSource1.FromStreamImpl(String name, Func1 imageStream, Nullable1 quality) at MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes.ImageSource.FromStream(String name, Func1 imageStream, Nullable1 quality) at PdfSharpCore.Drawing.XImage..ctor(Func1 stream) at PdfSharpCore.Drawing.XImage.FromStream(Func1 stream) at x.d__75.MoveNext() in x:line 917