Reset Scale in GDI + Conversion Matrix

I am writing a function to draw user interface handles (rotate, resize, etc.) in my client area in a Windows Forms application. The function is called when an object is selected.

The caller sends me a graphic object that is correctly rotated, scaled, and translated to fit into a large scheme of things (the selected object has its own rotation / translation / scale, and the interface handle has relative translation and rotation for the selected object). Now I want my user interfaces to be the same size regardless of the scale of the parent (selected object).

How to eliminate / reset the scale factor in the transformation matrix? How to reset on a scale of 1 while maintaining valuable translation and rotation values?

+3
source share
2 answers

Antigranitic geometry uses the basic method to determine the scaling of a transform (an implementation is found in agg_trans_affine.cpp). This is done like this:

  • Conversion rotation calculation
  • Transform duplication and reverse rotation
  • Convert two known points and calculate the scale from the result

Translated to C #, it looks like this:

Matrix transform = (Matrix)graphics.Transform.Clone();

PointF[] rotationPoints = new PointF[] { new PointF(0, 0), new PointF(1, 0) };
transform.TransformPoints(rotationPoints);

double rotationRadians = Math.Atan2(rotationPoints[1].Y - rotationPoints[0].Y, rotationPoints[1].X - rotationPoints[0].X);
transform.Rotate((float)(-rotationRadians * (180.0 / Math.PI)));

PointF[] scalePoints = new PointF[] { new PointF(0, 0), new PointF(1, 1) };
transform.TransformPoints(scalePoints);

float xScale = scalePoints[1].X - scalePoints[0].X;
float yScale = scalePoints[1].Y - scalePoints[0].Y;

AGG , , , .

+1

, . "" (, ).

, ( currentscale) 1/currentscale .

+1

Source: https://habr.com/ru/post/1708061/


All Articles