3
我想使用GDI +在後臺線程上渲染圖像。我發現this example關於如何使用GDI +旋轉圖像,這是我想要做的操作。GDI +:如何將Graphics對象渲染爲後臺線程上的位圖?
private void RotationMenu_Click(object sender, System.EventArgs e)
{
Graphics g = this.CreateGraphics();
g.Clear(this.BackColor);
Bitmap curBitmap = new Bitmap(@"roses.jpg");
g.DrawImage(curBitmap, 0, 0, 200, 200);
// Create a Matrix object, call its Rotate method,
// and set it as Graphics.Transform
Matrix X = new Matrix();
X.Rotate(30);
g.Transform = X;
// Draw image
g.DrawImage(curBitmap,
new Rectangle(205, 0, 200, 200),
0, 0, curBitmap.Width,
curBitmap.Height,
GraphicsUnit.Pixel);
// Dispose of objects
curBitmap.Dispose();
g.Dispose();
}
我的問題有兩個部分:
你將如何完成
this.CreateGraphics()
在後臺線程?可能嗎?我的理解是這個例子中的UI對象是this
。所以如果我在後臺線程上做這個處理,我將如何創建一個圖形對象?然後,我會如何從我正在使用的圖形對象中提取一個位圖,一旦完成處理?我一直無法找到一個如何做到這一點的好例子。
另外:格式化代碼示例時,我該如何添加新行?如果有人可以給我留言,說明我真的很感激。謝謝!
啊,這很有趣。這絕對清除了一些謎團。我會嘗試的。謝謝! – 2009-05-27 18:40:57