Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# PDFsharp图像到XImage_C#_Asp.net_Pdfsharp - Fatal编程技术网

C# PDFsharp图像到XImage

C# PDFsharp图像到XImage,c#,asp.net,pdfsharp,C#,Asp.net,Pdfsharp,我在ASP.NET MVC应用程序中创建了一个条形码作为图像 BarcodeLib.Barcode barcode = new BarcodeLib.Barcode() { IncludeLabel = false, Alignment = AlignmentPositions.LEFT, Width = element.BarcodeWidth, Height = elemen

我在ASP.NET MVC应用程序中创建了一个条形码作为图像

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
 };
这将使用条形码库创建条形码。
如何将其转换为PDFsharp的最大值

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

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


使用任何PDFsharp版本,您都可以将PNG图像写入MemoryStream,然后从该MemoryStream中获取最大值。

通过以下方式解决此问题:

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);
而且, 如果您知道图像路径,您可以使用它

XImage xImage = XImage.FromFile(imagePath)

实际上,方法在.net核心版本中已经更改。它以Func为参数。请注意:这是.NETCore的非官方版本

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

还有
XImage.FromStream
,因此您可以添加在MemoryStream中创建的图像。你需要1.5版,你确定吗?请看一下这个方法,然后我们可以讨论它看起来像PDFsharp的非官方端口(我不知道是哪个)。最有可能的是,在2017年提出这个问题时,它并不存在。在没有明确标识特殊端口所属的端口的情况下,说明特殊端口的特殊扩展是没有用的。没错,这是一个非正式的扩展,但这对.net core非常有用,否则您必须更改大部分内容。所以请纠正你的得分。