[Mono-list] OutOfMemoryException after scale transform a Region

Pablo Lecea plecea at belatrixsf.com
Mon Sep 22 11:46:22 EDT 2008

Hello there,
I have an application which takes two Regions and gets the intersection
between both in order to get the closest point... Before the intersect
operation is figured out I'm scaling the regions to avoid roundings. But
after the regions are scaled (100) any operation against the regions can be
done without get a OutOfMemoryException. This is happening just on Mac OS, I
tested on Windows XP via mono and it works fine.
The exception message is : 
** (/Users/pablolecea/closest/closest/bin/Debug/closest.exe:604): WARNING
**: Path conversion requested 42830368 bytes (2936 x 3647). Maximum size is
8388608 bytes.

Unhandled Exception: System.OutOfMemoryException: Not enough memory to
complete operation [GDI+ status: OutOfMemory]
  at System.Drawing.GDIPlus.CheckStatus (Status status) [0x000be] in
  at System.Drawing.Region.Intersect (System.Drawing.Region region)
[0x00024] in
  at (wrapper remoting-invoke-with-check) System.Drawing.Region:Intersect
  at closest.MainClass.GetClosestPoint () [0x00030] in
  at closest.MainClass.Main (System.String[] args) [0x00000] in

Here the code:

static void Main(string[] args)

private static void GetClosestPoint()
            //get the regions
            Region firstRegion = CreateFirstRegion();
            Region secondRegion = CreateSecondRegion();

            //This scaling is done to avoid rounding in bounds values
            Matrix matrix = new Matrix();
            matrix.Scale(100, 100);

            //intersect the regions
            firstRegion.Intersect(secondRegion); //an OutOfMemoryException
is thrown on mac OS

            System.Windows.Forms.Control control = new
            System.Drawing.Graphics graph = control.CreateGraphics();
            graph.PageUnit = GraphicsUnit.Pixel;
            System.Drawing.RectangleF bounds = firstRegion.GetBounds(graph);


private static Region CreateFirstRegion()
            GraphicsPath gp = new GraphicsPath();

            gp.AddLine(new PointF(193.24475f, 189.1613f), new
PointF(221.7687f, 225.011f));
            gp.AddLine(new PointF(221.7687f, 225.011f), new
PointF(222.5512f, 224.38869f));
            gp.AddLine(new PointF(222.5512f, 224.38869f), new
PointF(194.0272f, 188.53869f));

            Region result = new Region(gp);
            return result;

        private static Region CreateSecondRegion()
            GraphicsPath gp = new GraphicsPath();
            string text = "Cl";
            int platformStyle = (int)System.Drawing.FontStyle.Regular;
            float fontSize = 12;
            string fontName = "Times New Roman";

            System.Drawing.Font platformFont = new
System.Drawing.Font(fontName, fontSize, System.Drawing.FontStyle.Regular,
            gp.AddString(text, platformFont.FontFamily, platformStyle,
platformFont.Size, new System.Drawing.Rectangle(),

            Matrix translationMatrix = new Matrix();
            translationMatrix.Translate(187.222f, 182.8066f);

            Region result = new Region(gp);
            return result;

Can you help me to figure out what is happening.
View this message in context: http://www.nabble.com/OutOfMemoryException-after-scale-transform-a-Region-tp19610028p19610028.html
Sent from the Mono - General mailing list archive at Nabble.com.

More information about the Mono-list mailing list