Subject: Arithmetic operation resulted in an overflow on Graphics.PdfGraphics.DrawImage
Date: 2014-08-05 13:24:08
From: Yaakov Ellis
Source: arithmetic-operation-resulted-overflow-graphics-pdfgraphics-drawimage
----------------------------------------------------------------------

I have the following code:

            [code lang='c#']elem.Graphics.DrawImage(PdfImage.FromImage(Resources.se_logo), new PointF(0, 0), new SizeF(34, 41));[/code]

This is included in a function in a class library method that returns a PdfDocument object.

se_logo is an image included in a Resources file, with the source image set with "Embedded Resource" as a build action and Embedded in .resx set for the Image in the resource file.

Included in a the same solution is a demo project that references the class library and uses it to output a pdf. Works without any issues.

I am now using the class library in a different project, different solution (distributed through private nuget feed, though that shouldn't make a difference). When I try to run the exact same call on the class library (which works in the demo project), I get the following exception:

Arithmetic operation resulted in an overflow.

[OverflowException: Arithmetic operation resulted in an overflow.]
   System.IntPtr.ToInt32() +37
   ComponentPro.Pdf.Graphics.PdfBitmap.c_X1R() +423
   ComponentPro.Pdf.Graphics.PdfBitmap.c_L1R() +628
   ComponentPro.Pdf.Graphics.PdfBitmap.c_RBC() +70
   ComponentPro.Pdf.Graphics.PdfBitmap.c_N1R() +787
   ComponentPro.Pdf.Graphics.PdfBitmap.c_RBC() +78
   ComponentPro.Pdf.Graphics.PdfGraphics.DrawImage(PdfImage image, Single x, Single y, Single width, Single height) +225
   ComponentPro.Pdf.Graphics.PdfGraphics.DrawImage(PdfImage image, PointF point, SizeF size) +85

I am verifying in code that the Image is present, and have tried separating out the line where the PdfImage.FromImage() function is called (no exception there). The exception always happens in DrawImage.

Any idea what could be the issue here? Any recommended way of distributing images embedded in a class library for use in a situation like this where it will not throw an exception?

 

---------------------------------------------------------------------- Note: This question has been asked on the Q&A forum of Thang Dang's fraudulent ComponentPro brand If you purchased anything from ComponentPro, you have been scammed. Contact the payment processor who sold you the license and ask for your money back. Back to ComponentPro Q&A Forum Index