PdfSharpCore icon indicating copy to clipboard operation
PdfSharpCore copied to clipboard

PdfSharpCore.Drawing.XImage.FromFile Error

Open 3400442579 opened this issue 2 years ago • 2 comments

System.MissingMethodException: Method not found: 'SixLabors.ImageSharp.Image1<!!0> SixLabors.ImageSharp.Image.Load(System.String, SixLabors.ImageSharp.Formats.IImageFormat ByRef)'. at PdfSharpCore.Utils.ImageSharpImageSource1.FromFileImpl(String path, Nullable1 quality) at MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes.ImageSource.FromFile(String path, Nullable1 quality) at PdfSharpCore.Drawing.XImage..ctor(String path) at PdfSharpCore.Drawing.XImage.FromFile(String path, PdfReadAccuracy accuracy) at PdfSharpCore.Drawing.XImage.FromFile(String path)

            var page = document.AddPage();
            var gfx = PdfSharpCore.Drawing.XGraphics.FromPdfPage(page);
            gfx.DrawImage(PdfSharpCore.Drawing.XImage.FromFile(@"E:\Dev\Copyright\Web\zdoc\1\signature.png"), new PdfSharpCore.Drawing.XPoint(0, 0));
            document.Save(Path.Combine(path, "signature.pdf"));

3400442579 avatar Oct 20 '23 08:10 3400442579

I also had this issue, you can fix it by downgrading your SixLabors.ImageSharp version to 2.* in you csproj like so: <PackageReference Include="SixLabors.ImageSharp" Version="2.*" /> or I guess the following merge request could fix it, if someone would accept it: #400

LewxX avatar Oct 21 '23 11:10 LewxX

still not fixed this, I had to patch it myself so I could use the last version of the library. You just need to extend the class ImageSource as he did with ImageSharpImageSource. The bug is in this method that changed in the lasts upgrades of the library: SixLabors.ImageSharp.Image.Load now only accepts ONE parameter instead of two.

` protected override IImageSource FromBinaryImpl(string name, Func<byte[]> imageSource, int? quality = 75) { ArgumentNullException.ThrowIfNull(imageSource);

var source = imageSource();
Image image = Image.Load(source);
return new ImageSharpImageSourceImplementation(name, image, quality.Value, image.Metadata.DecodedImageFormat is 
PngFormat);
}

`

Here´s an example of an override method I extended in my new class.

alexariza95 avatar Feb 21 '24 08:02 alexariza95