我从MetaFile(emf)绘制图像,然后在UserControl的OnPaint中对其应用一些旋转变换。应用那些转换后,我怎样才能计算出这个在屏幕坐标中的正常未转换的矩形边界框?我需要这个能够将旋转的图像调整到UserControl的大小。计算GDI +绘图的边界框
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);
}
这背后的整个想法是,我想要显示的.emf在用户控件文件旋转并具有电动势绘图永诺填写用户控件的可用空间。也许有更好的方法?
我后面的fillmode/stretchmode是Uniform和UniformToFill(就像在WPF的Viewbox中一样)。 emf不应该在Uniform模式下被扭曲,emf至少在一个维度上完全填充usercontrol,没有任何东西被裁剪。在UniformToFill中,emf填充两个维度中的UserControl,并且如果宽高比不匹配,emf将在一个维度上裁剪。
你想如何“填补”?如果emf完全覆盖usercontrol(emf的某些部分应该裁剪)还是应该调整大小以便所有的emf都可见 - 留下部分用户控件? emf应该保持原始的宽高比吗? – 2009-11-23 07:47:46
我后面的fillmode/stretchmode是Uniform和UniformToFill(就像在WPF的Viewbox中一样)。 emf不应该在Uniform模式下被扭曲,emf至少在一个维度上完全填充usercontrol,没有任何东西被裁剪。在UniformToFill中,emf填充两个维度中的UserControl,并且如果宽高比不匹配,emf将在一个维度上裁剪。 – bitbonk 2009-11-23 09:52:27