0

System.ArgumentException: 'Parameter is not valid.'

This is the first time I have tried to toy with a Matrix and transformations. Anywho...

protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.Transform = m_Vars.TransformMatrix;
            g.Clear (m_Vars.ClearColor);

            g.FillRectangle (m_Vars.FillBrush , m_Vars.DrawRectangle);
            g.DrawRectangle (m_Vars.LinePen , m_Vars.DrawRectangle);

            if (m_Vars.DrawCrossSection)
            {
                g.DrawLine (m_Vars.LinePen , m_Vars.DrawRectangle_TopMidpoint , m_Vars.DrawRectangle_BottomMidpoint);
                g.DrawLine (m_Vars.LinePen , m_Vars.DrawRectangle_LeftMidpoint , m_Vars.DrawRectangle_RightMidpoint);
            }

            Invalidate ();
        }

Exception is thrown at "g.Transform = m_Vars.TransformMatrix". Locals reveals my desired -new- matrix has 6 values: 0.1, 0.0 0.0, 0.0 0.0, 0.0

-- When I create this replacement transform matrix, I use "new Matrix()' which creates an identity matrix.

Is my new matrix the issue or is System.Drawing the issue? Also, any kind of work around perhaps?

  • System.Drawing is never the issue when it tells you that you are using it wrong. So yes, your matrix is wrong, GDI+ does not support non-linear transforms. Consider using the Matrix methods to convert the identity matrix to the one you want. – Hans Passant Mar 19 '19 at 11:38
  • These are my matrix creation lines. newMatrix.Shear((float)m_TransformMatrixSheerXNumericUpDown.Value, (float)m_TransformMatrixSheerYNumericUpDown.Value); newMatrix.Scale((float)m_TransformMatrixScaleXNumericUpDown.Value, (float)m_TransformMatrixScaleYNumericUpDown.Value); newMatrix.Translate((float)m_TransformMatrixTranslateXNumericUpDown.Value, (float)m_TransformMatrixTranslateYNumericUpDown.Value); newMatrix.Rotate((float)m_TransformMatrixRotateNumericUpDown.Value); – Furry Chemistry Mar 19 '19 at 18:12
  • "https://learn.microsoft.com/en-us/dotnet/framework/winforms/advanced/using-the-world-transformation" explains what goes on when I call these methods, but doesn't seem to say anything about assigning a matrix to Graphics.Transform. I would like to know why assigning the matrix to the graphics doesn't work. "https://learn.microsoft.com/en-us/windows/desktop/gdiplus/-gdiplus-matrix-representation-of-transformations-about" also has more info about matrices. – Furry Chemistry Mar 19 '19 at 18:18
  • Through System.Drawing.Graphics :: Sheer does nothing (only via Graphics.Transform.Shear(dx, dy)). Scale must be greater than zero. Rotate works and translate works. – Furry Chemistry Mar 19 '19 at 19:28

0 Answers0