NullReferenceException when using ImageStream

I'm trying to get an image from a memory stream into the pdf document using the following code:

Dim bitmap As Bitmap
Dim g As Graphics
Dim hatchBrush As Drawing2D.HatchBrush
Dim stream As MemoryStream
Dim pdf As Aspose.Pdf.Pdf
Dim section As Aspose.Pdf.Section
Dim image As Aspose.Pdf.Image

bitmap = New Bitmap(81, 21, Imaging.PixelFormat.Format32bppArgb)
g = Graphics.FromImage(bitmap)
g.Clear(Color.White)
hatchBrush = New Drawing2D.HatchBrush(Drawing2D.HatchStyle.Cross, Color.Blue, Color.White)
g.FillRectangle(hatchBrush, 0, 20, 80, 20)
g.DrawRectangle(Pens.Black, 0, 20, 80, 20)
hatchBrush.Dispose()
stream = New MemoryStream
bitmap.Save(stream, Imaging.ImageFormat.Png)
pdf = New Aspose.Pdf.Pdf
section = pdf.Sections.Add()
image = New Aspose.Pdf.Image
image.ImageInfo.ImageFileType = Aspose.Pdf.ImageFileType.Png
image.ImageInfo.ImageStream = stream
section.Paragraphs.Add(image)
pdf.Save("C:\Test.pdf")

Executing the code result in a NullReferenceException. Is my code incorrect or a result of a bug?

Thanks!

Hi,

Thank you for considering Aspose.

I have checked with latest version of Aspose.pdf (3.5.1.0) and I am unable to reproduce the error. Please make sure that you are using the latest version. I have only changed the color.white to System.Drawing.Color.White. I am also attaching the output for your reference.

Thanks.

Adeel Ahmad
Support Developer
Aspose Changsha Team

Correct, working fine now. Thanks!