Calculate GDI + drawing bounding box

I draw an image from MetaFile (emf) and then apply some rotation transformations to everything inside the OnPaint UserControl. After applying these transformations, how can I calculate the normal non-transformed rectangular bounding rectangle of this in screen coordinates? I need this to be able to resize the rotated image to the size of a UserControl.

protected override void OnPaint(PaintEventArgs e)
{
    // rotate around the center of this UserControl
    e.Graphics.TranslateTransform(this.Width / 2.0f, this.Height / 2.0f);
    e.Graphics.RotateTransform(this.Rotation);
    e.Graphics.TranslateTransform(this.Width / -2.0f, this.Height / -2.0f);

    // TODO: now scale so the image so it fits exactly into this UserControl

    // draw the image at the center of this UserControl
    float left = (this.Width - ResourceManager.MyDrawingMetaFile.Width) / 2.0f;
    float top = (this.Height - ResourceManager.MyDrawingMetaFile.Height) / 2.0f;
    e.Graphics.DrawImage(Resources.MyDrawingMetaFile, left, top);
}

The whole idea is that I want to display the rotated .emf file in UserControl, and the emf picture always fills the available space in UserControl. Maybe there is a better approach?

/, , Uniform UniformToFill ( WPF Viewbox). . , , , . UniformToFill emf UserControl , aspectratios , emf .

+3
2

- , , .

:

  • [].
  • (.RotateAt)
  • .
  • X (pts [3].X - pts [0].X ).
  • , .
  • 4 .
+1

GDI:

BeginPath()
// Draw stuff
EndPath()
PathToRegion()
GetRgnBox()

GDI + - GraphicsPath Region

0

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


All Articles