2017-06-03 59 views
0

我创建了一个条形码在我的ASP.NET MVC应用程序的图像。PDFsharp图像XImage

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 
}; 

这将使用BarcodeLib创建一个条形码。
如何将其转换为PDFsharp的XImage?

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

回答

1

如果使用PDFsharp的GDI构建,那么你可以调用XImage.FromImage方法。

随着PDFsharp的任何构建你可以写一个PNG图像到一个MemoryStream,然后从那个MemoryStream的一个XImage。

+0

还有'XImage.FromStream',这样你就可以添加一个MemoryStream创建的图像。你需要1.5版本。 – VDWWD

0

解决这样说:

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);