我從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