Search code examples
imagepdfxamarinstreamsyncfusion

Syncfusion Xamarin 'Value cannot be null. Parameter name: stream' during adding image


I would like to load image to pdf from stream. When I try to do that I get an error

System.ArgumentNullException: 'Value cannot be null.
Parameter name: stream'

Here is my code

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

Solution

  • Firstly , in this way you need to put the image in Forms project instead of Android project .In my demo I put the image in the folder Assets . And the code should like the following

    enter image description here

    var assembly = this.GetType().GetTypeInfo().Assembly;
    Stream s = assembly.GetManifestResourceStream("MyApp.Assets.icon.png");
    

    In addition , make sure that the build action of the image is Embeddded Resource

    Right Click the image -> Properties

    enter image description here