I am drawing an image from MetaFile (emf) and then apply some rotation transformations to it all within the OnPaint of a UserControl. After applying those transformation how can I calculate the normal untransformed rectangular bounding box of this in screen coordinates? I need this to be able to resize the rotated image to the size of the 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 behind this is that I want to display rotated .emf File in a UserControl and have the emf drawing allways fill the available space in the UserControl. Maybe there is a better approach?
The fillmode/stretchmode I am after is Uniform and UniformToFill (like in WPF's Viewbox). The emf should not be distorted an in Uniform mode the emf completely fills the usercontrol at least in one dimension, nothing is cropped. In UniformToFill the emf filles the UserControl in both dimensions and if the aspectratios do not match, the emf is cropped in one dimension.