次の方法で共有


Renderer.Draw メソッド (Bitmap, Stroke, DrawingAttributes)

指定した DrawingAttributes を使用して、指定した BitmapStroke を描画します。

名前空間 :  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
)

パラメータ

この例では、InkOverlay オブジェクトに関連付けられた Ink オブジェクトの Strokes コレクション全体が、ファイルから読み込まれたビットマップ イメージ上に描画されます。

さらに、ビットマップ イメージ上に Stroke オブジェクトを描画するときに、変更された DrawingAttributes オブジェクトが使用されます。ストロークの色を反転し、幅を倍にするという変更が適用されます。変更された DrawingAttributes オブジェクトは、次に da パラメータを介して 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

参照

参照

Renderer クラス

Renderer メンバ

Draw オーバーロード

Microsoft.Ink 名前空間