【发布时间】:2010-12-19 06:27:37
【问题描述】:
我正在从 MetaFile (emf) 中绘制图像,然后在 UserControl 的 OnPaint 中对其应用一些旋转变换。应用这些转换后,我如何计算屏幕坐标中正常的未转换矩形边界框?我需要这个能够将旋转图像的大小调整为 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);
}
这背后的整个想法是我想在 UserControl 中显示旋转的 .emf 文件,并让 emf 绘图始终填充 UserControl 中的可用空间。也许有更好的方法?
我所追求的填充模式/拉伸模式是 Uniform 和 UniformToFill(就像在 WPF 的 Viewbox 中一样)。 emf 不应该被扭曲,在 Uniform 模式下,emf 至少在一个维度上完全填充用户控件,没有任何东西被裁剪。在 UniformToFill 中,emf 在两个维度上填充 UserControl,如果纵横比不匹配,则在一个维度上裁剪 emf。
【问题讨论】:
-
您希望它如何“填充”? emf 应该完全覆盖用户控件(应该裁剪 emf 的某些部分)还是应该调整大小以使所有 emf 都可见 - 让用户控件的部分被覆盖? emf 是否应该保持原来的纵横比?
-
我追求的 fillmode/stretchmode 是 Uniform 和 UniformToFill(就像在 WPF 的 Viewbox 中一样)。 emf 不应该被扭曲,在 Uniform 模式下,emf 至少在一个维度上完全填充用户控件,没有任何东西被裁剪。在 UniformToFill 中,emf 在两个维度上填充 UserControl,如果纵横比不匹配,则在一个维度上裁剪 emf。
标签: c# gdi+ resize bounding-box