Search

Atalasoft Knowledge Base

FIX: TextAnnotation throws an exception in DrawString

Administrator
DotImage

It has been found that rendering a TextAnnotation can, at times, cause a System.ArgumentException when the Graphics.DrawString method is used. This is not specific to DotAnnotate and appears to be a bug in the .NET Framework.

The exception will appear as follows:

System.ArgumentException: 
Parameter is not valid.at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
  at System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
  at Atalasoft.Imaging.Annotate.TextAnnotation.Paint(Graphics graphics, PointF offset, PointF zoom, Single resolution)

This seems to only happen when a brush from the static Brushes object is used. For example:

TextAnnotation ann = new TextAnnotation("My Text", font, Brushes.Black, null, null);

This can be resolved by creating a new SolidBrush instead:

TextAnnotation ann = new TextAnnotation("My Text", font, new SolidBrush(Color.Black), null, null);

Original Article:
Q10145 - FIX: TextAnnotation throws an exception in DrawString

Details
Last Modified: Last Week
Last Modified By: Administrator
Type: FIX
Article not rated yet.
Article has been viewed 12 times.
Options
Also In This Category