PDFsharp image to XImage

Viewed 14434

I created a barcode as an image in my ASP.NET MVC app.

BarcodeLib.Barcode barcode = new BarcodeLib.Barcode()                   
{                        
    IncludeLabel = false,
    Alignment = AlignmentPositions.LEFT,
    Width = element.BarcodeWidth,
    Height = element.BarcodeHeight,
    RotateFlipType = RotateFlipType.RotateNoneFlipNone,
    BackColor = Color.Transparent,
    ForeColor = Color.Black,
    ImageFormat = System.Drawing.Imaging.ImageFormat.Png
 };

This will create a barcode with the BarcodeLib.
How do I convert it to an XImage of PDFsharp?

Image img = barcode.Encode(TYPE.CODE128, "123456789");
gfx.DrawImage(xImage, 0, 0, 100, 100);
4 Answers

Actually method had been changed in .net core version. It takes Func as parameter. Attention please: It's unofficial version for .net core.

XImage xImage = XImage.FromStream(() => new MemoryStream(yourByte[]));

Also, If you know image path you can use that

XImage xImage = XImage.FromFile(imagePath)
Related