Renderer.Draw 方法 (Bitmap, Stroke, DrawingAttributes)
以指定的 DrawingAttributes 在指定的 Bitmap 上繪製 Stroke。
命名空間: Microsoft.Ink
組件: Microsoft.Ink (在 Microsoft.Ink.dll 中)
語法
'宣告
Public Sub Draw ( _
destinationBitmap As Bitmap, _
stroke As Stroke, _
da As DrawingAttributes _
)
'用途
Dim instance As Renderer
Dim destinationBitmap As Bitmap
Dim stroke As Stroke
Dim da As DrawingAttributes
instance.Draw(destinationBitmap, stroke, _
da)
public void Draw(
Bitmap destinationBitmap,
Stroke stroke,
DrawingAttributes da
)
public:
void Draw(
Bitmap^ destinationBitmap,
Stroke^ stroke,
DrawingAttributes^ da
)
public void Draw(
Bitmap destinationBitmap,
Stroke stroke,
DrawingAttributes da
)
public function Draw(
destinationBitmap : Bitmap,
stroke : Stroke,
da : DrawingAttributes
)
參數
- destinationBitmap
型別:System.Drawing.Bitmap
要在上面進行繪製的指定的 Bitmap。
- stroke
型別:Microsoft.Ink.Stroke
要繪製的 Stroke。
- da
型別:Microsoft.Ink.DrawingAttributes
要使用的 DrawingAttributes。
範例
在這個範例中,會將來自與 InkOverlay 物件相關聯之 Ink 物件的整個 Strokes 集合繪製到已從檔案載入的點陣圖上。
此外,在點陣圖上繪製 Stroke 物件時,會使用修改過的 DrawingAttributes 物件。所套用的修改包含反轉筆劃的色彩,以及筆劃寬度放大兩倍。然後,會透過 da 參數將修改過的 DrawingAttributes 物件傳遞至 Draw 方法。這不會影響原始筆劃的 DrawingAttributes。
呼叫 Draw 方法並不會顯示影像和筆劃。相反地,它會將筆劃呈現資料與點陣圖資料合併,以準備顯示。藉由呼叫與 Panel (英文) 物件相關聯之 Graphics (英文) 物件的 DrawImage 方法,使點陣圖 (現在已使用筆劃呈現資料加以修改) 成為可見的。
' get the Bitmap object loaded from a file
' scale the image to match the panel size
Dim bgImage As Bitmap = New Bitmap(New Bitmap(imageFileName), Me.panelForDraw.Size)
' Access to the Ink.Strokes property returns a copy of the Strokes object.
' This copy must be implicitly (via using statement) or explicitly
' disposed of in order to avoid a memory leak.
Using allStrokes As Strokes = mInkOverlay.Ink.Strokes
' get a Renderer object. We could have used
' mInkOverlay.Renderer, this is another way
Dim R As Renderer = New Renderer()
' traverse the stroke collection
For Each oneStroke As Stroke In allStrokes
Dim da As DrawingAttributes = oneStroke.DrawingAttributes.Clone()
' invert the stroke color
Dim cR As Byte = Not da.Color.R
Dim cG As Byte = Not da.Color.G
Dim cB As Byte = Not da.Color.B
da.Color = Color.FromArgb(da.Color.A, cR, cG, cB)
' double the stroke width
da.Width *= 2
' draw the stroke
R.Draw(bgImage, oneStroke, da)
Next
End Using
' now display the bitmap (with the strokes) on the panel
Using g As Graphics = Me.panelForDraw.CreateGraphics()
g.DrawImage(bgImage, 0, 0)
End Using
bgImage.Dispose()
// get the Bitmap object loaded from a file
// scale the image to match the panel size
Bitmap bgImage = new Bitmap(new Bitmap(imageFileName), this.panelForDraw.Size);
// Access to the Ink.Strokes property returns a copy of the Strokes object.
// This copy must be implicitly (via using statement) or explicitly
// disposed of in order to avoid a memory leak.
using (Strokes allStrokes = mInkOverlay.Ink.Strokes)
{
// get a Renderer object. We could have used
// mInkOverlay.Renderer, this is another way
Renderer R = new Renderer();
// traverse the stroke collection
foreach (Stroke oneStroke in allStrokes)
{
DrawingAttributes da = oneStroke.DrawingAttributes.Clone();
// invert the stroke color
byte cR = (byte)~(da.Color.R);
byte cG = (byte)~(da.Color.G);
byte cB = (byte)~(da.Color.B);
da.Color = Color.FromArgb(da.Color.A, cR, cG, cB);
// double the stroke width
da.Width *= 2;
// draw the stroke
R.Draw(bgImage, oneStroke, da);
}
}
// now display the bitmap (with the strokes) on the panel
using (Graphics g = this.panelForDraw.CreateGraphics())
{
g.DrawImage(bgImage, 0, 0);
}
bgImage.Dispose();
平台
Windows Vista
.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求。
版本資訊
.NET Framework
支援版本:3.0