We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

PDF: DrawImage function stopped working

I had code that simply writes an Image to a PDF page.
Worked for weeks. All of a sudden, the working code suddenly stopped working.
PdfBitmapimage=newPdfBitmap(newMemoryStream(sub.TheImage));				//validimagedata
graphics.DrawImage(image,0,0,page.Graphics.ClientSize.Width,page.Graphics.ClientSize.Height);	//<==suddenlyraisesexception	

The problem is with
graphics.DrawImage(image,0,0,page.Graphics.ClientSize.Width,page.Graphics.ClientSize.Height);		//<==suddenlyraisesexception

This raises a NullReferenceException - although NOTHING in here has a null value: not the sub.TheImage object, not the graphics object, not the image object, neither the ClientSize.
This once working code just all of a sudden stopped working. There mus be a problem with the .DrawImage() function with one of the latest windows updates. I see no other explanation.

4 Replies

WB Wolfgang Brucker June 20, 2017 09:09 AM UTC

Exception is:

+  ex {System.NullReferenceException: Object reference not set to an instance of an object.
   at Syncfusion.Pdf.Graphics.PdfBitmap.SetColorSpace()
   at Syncfusion.Pdf.Graphics.PdfBitmap.Save()
   at Syncfusion.Pdf.Graphics.PdfGraphics.DrawImage(PdfImage image, Single x, Single y, Single width, Single height)
   at Scan10.Views.MainPage.<ExportAsPDF>d__23.MoveNext()} System.Exception {System.NullReferenceException}

SK Surya Kumar Syncfusion Team June 21, 2017 02:04 PM UTC

Hi Wolfgang, 
Thank you for using Syncfusion products, 
We have tried to reproduce the issue which you have mentioned, with the code snippet which you have given, but we are unable to reproduce the same. 
Please find the sample in which we tried to reproduce the issue from the below link, if you can still reproduce the issue, please modify the code in sample attached and share the image file with which the issue is reproduced. 
Sample Link: 
Surya Kumar 

WB Wolfgang Brucker June 21, 2017 02:29 PM UTC

The problem seems to be related to BMP images only.  Some BMP images do work while some others DO NOT WORK and raise a NullReference exception. The exception above is real, not from a dream.  So as a workaround I now convert every BMP to a PNG and load that tmp PNG from stream to PdfBitmap.  That does work where the original BMP failed.  But this doesn't speed up my app, you know...   Nevertheless I would consider this to be a bug because according to your documentation BMPs should do fine which is not true in any case.  Maybe the problem has to do with the image dimensions?  I am not using little images like 320x240 but very large ones (2700 x 1900).

SK Surya Kumar Syncfusion Team June 22, 2017 11:26 AM UTC

Hi Wolfgang,  
We have created separate incident to follow up the issue with” Null reference exception occurs while drawing the BMP image to PDF in UWP platform” which can be tracked from below link: 
Surya Kumar 

Live Chat Icon For mobile
Up arrow icon