添加图像期间 Syncfusion Xamarin 'Value cannot be null. Parameter name: stream'
Syncfusion Xamarin 'Value cannot be null. Parameter name: stream' during adding image
我想从流中加载图像到 pdf。当我尝试这样做时,出现错误
System.ArgumentNullException: 'Value cannot be null.
Parameter name: stream'
这是我的代码
Stream imageStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("MyApp.Resources.drawable.image.png");
PdfImage image = PdfImage.FromStream(imageStream); <---- here is error
g.DrawImage(image, new PointF(20, 20));
首先,通过这种方式,您需要将图像放在 Forms 项目而不是 Android 项目中。在我的演示中,我将图像放在文件夹 Assets 中。代码应该如下所示
var assembly = this.GetType().GetTypeInfo().Assembly;
Stream s = assembly.GetManifestResourceStream("MyApp.Assets.icon.png");
此外,请确保图像的构建操作是Embedded Resource
右键单击图像 -> 属性
我们已经检查了将图像从流加载到 pdf 的问题,但它工作正常。并且图像被加载并插入到 Pdf 文档中,并确保图像的构建操作是 Embeddded Resource。请尝试以下文档中的示例,并让我们知道结果。
KB : https://www.syncfusion.com/kb/10375/how-to-insert-an-image-into-pdf-in-xamarin
UG : https://help.syncfusion.com/file-formats/pdf/working-with-images
注意:我在Syncfusion工作。
我想从流中加载图像到 pdf。当我尝试这样做时,出现错误
System.ArgumentNullException: 'Value cannot be null.
Parameter name: stream'
这是我的代码
Stream imageStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("MyApp.Resources.drawable.image.png");
PdfImage image = PdfImage.FromStream(imageStream); <---- here is error
g.DrawImage(image, new PointF(20, 20));
首先,通过这种方式,您需要将图像放在 Forms 项目而不是 Android 项目中。在我的演示中,我将图像放在文件夹 Assets 中。代码应该如下所示
var assembly = this.GetType().GetTypeInfo().Assembly;
Stream s = assembly.GetManifestResourceStream("MyApp.Assets.icon.png");
此外,请确保图像的构建操作是Embedded Resource
右键单击图像 -> 属性
我们已经检查了将图像从流加载到 pdf 的问题,但它工作正常。并且图像被加载并插入到 Pdf 文档中,并确保图像的构建操作是 Embeddded Resource。请尝试以下文档中的示例,并让我们知道结果。
KB : https://www.syncfusion.com/kb/10375/how-to-insert-an-image-into-pdf-in-xamarin
UG : https://help.syncfusion.com/file-formats/pdf/working-with-images
注意:我在Syncfusion工作。