Metodo Renderer.Draw (Bitmap, Stroke, DrawingAttributes)
Aggiornamento: novembre 2007
Disegna l'oggetto Stroke sull'oggetto Bitmap specificato con l'oggetto DrawingAttributes specificato.
Spazio dei nomi: Microsoft.Ink
Assembly: Microsoft.Ink (in Microsoft.Ink.dll)
Sintassi
'Dichiarazione
Public Sub Draw ( _
destinationBitmap As Bitmap, _
stroke As Stroke, _
da As DrawingAttributes _
)
'Utilizzo
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
)
Parametri
- destinationBitmap
Tipo: System.Drawing.Bitmap
Oggetto Bitmap specificato sul quale disegnare.
- stroke
Tipo: Microsoft.Ink.Stroke
Oggetto Stroke da disegnare.
- da
Tipo: Microsoft.Ink.DrawingAttributes
DrawingAttributes da utilizzare.
Esempi
In questo esempio l'intero insieme Strokes di un oggetto Ink associato a un oggetto InkOverlay viene disegnato in un'immagine bitmap caricata da un file.
Inoltre, quando si disegnano gli oggetti Stroke sull'immagine bitmap, viene utilizzato un oggetto DrawingAttributes modificato. Vengono applicate delle modifiche tali da invertire il colore del tratto e raddoppiarne lo spessore. L'oggetto DrawingAttributes modificato viene quindi passato al metodo Draw tramite il parametro da. Tali operazioni non influiscono sulla proprietà DrawingAttributes dei tratti originali.
Chiamando il metodo Draw non si visualizzano l'immagine e i tratti. I dati di rendering del tratto vengono invece uniti ai dati dell'immagine bitmap in preparazione per la visualizzazione. L'immagine bitmap (appena modificata con i dati di rendering del tratto) viene resa visibile chiamando il metodo DrawImage dell'oggetto Graphics associato a un oggetto Panel.
' 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();
Piattaforme
Windows Vista
.NET Framework e .NET Compact Framework non supportano tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.
Informazioni sulla versione
.NET Framework
Supportato in: 3.0