Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDFsharp image to XImage

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);
like image 611
Tom el Safadi Avatar asked Aug 27 '26 21:08

Tom el Safadi


1 Answers

Solved it this way:

Image img = barcode.Encode(TYPE.CODE128, Name); // this is the image

MemoryStream strm = new MemoryStream();
img.Save(strm, System.Drawing.Imaging.ImageFormat.Png);

XImage xfoto = XImage.FromStream(strm);
like image 112
Tom el Safadi Avatar answered Aug 29 '26 12:08

Tom el Safadi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!