當我運行下面的代碼:C#,GDI + - 爲什麼我的矩形被截斷?
private void button1_Click(object sender, EventArgs e)
{
Bitmap b = new Bitmap(300, 400);
using (Graphics g = Graphics.FromImage(b))
{
g.FillRectangle(Brushes.Black, new Rectangle(0, 0, 300, 400));
}
b.RotateFlip(RotateFlipType.Rotate90FlipNone);
using (Graphics g2 = Graphics.FromImage(b))
{
g2.DrawRectangle(new Pen(Color.White, 7.2f), 200, 100, 150, 100);
}
using (Graphics g3 = this.panel1.CreateGraphics())
{
g3.DrawImage(b, 0, 0);
}
}
我得到如下:
alt text http://www.freeimagehosting.net/uploads/2c309ec21c.png
注:
它只有當我旋轉圖像發生了,再畫延伸超過圖像尺寸的原始的矩形。
矩形不會被截斷爲原始圖像的寬度 - 只是矩形的右邊緣沒有繪製。
這發生在各種情況下。我首先在一個更復雜的應用程序中注意到它 - 我只是寫了這個應用程序來簡單說明問題。
任何人都可以看到我做錯了什麼?
真棒 - 非常感謝! – mbeckish 2009-07-01 18:50:05