Ink.CreateStroke Method (array<Int32[], TabletPropertyDescriptionCollection)
Creates a Stroke object from packet data.
Namespace: Microsoft.Ink
Assembly: Microsoft.Ink (in Microsoft.Ink.dll)
Syntax
'Declaration
Public Function CreateStroke ( _
packetData As Integer(), _
tabletPropertyDescriptionCollection As TabletPropertyDescriptionCollection _
) As Stroke
'Usage
Dim instance As Ink
Dim packetData As Integer()
Dim tabletPropertyDescriptionCollection As TabletPropertyDescriptionCollection
Dim returnValue As Stroke
returnValue = instance.CreateStroke(packetData, _
tabletPropertyDescriptionCollection)
public Stroke CreateStroke(
int[] packetData,
TabletPropertyDescriptionCollection tabletPropertyDescriptionCollection
)
public:
Stroke^ CreateStroke(
array<int>^ packetData,
TabletPropertyDescriptionCollection^ tabletPropertyDescriptionCollection
)
public function CreateStroke(
packetData : int[],
tabletPropertyDescriptionCollection : TabletPropertyDescriptionCollection
) : Stroke
Parameters
packetData
Type: array<System.Int32[]The array of packet data used to make up the Stroke object.
tabletPropertyDescriptionCollection
Type: Microsoft.Ink.TabletPropertyDescriptionCollectionThe TabletPropertyDescriptionCollection collection that describes what properties are in the packetData array.
Return Value
Type: Microsoft.Ink.Stroke
The newly created stroke.
The newly created Stroke object.
Remarks
The size of the array in the packetData parameter must be divisible by the size of the tabletPropertyDescriptionCollection parameter.
Note
The first two elements of each packet in the the packetData parameter must be X and then Y. If X and Y are not specified in the first and second positions, respectively, of each packet, an ArgumentException is thrown.
Examples
In this example, a stroke representing an irregular sine wave is created from random packet data. First, the TabletPropertyMetrics for PacketPropertyX and Y are obtained in order to initialize the TabletPropertyDescriptionCollection with the TabletPropertyDescription objects for those PacketProperty types. If NormalPressure is supported on the default tablet, that too is added to the collection. Next, the actual packet data is created and passed to the CreateStroke method.
Dim allTablets As Tablets = New Tablets()
' get the property metrics for X and Y
Dim MetricX As TabletPropertyMetrics = allTablets.DefaultTablet.GetPropertyMetrics(PacketProperty.X)
Dim MetricY As TabletPropertyMetrics = allTablets.DefaultTablet.GetPropertyMetrics(PacketProperty.Y)
' create the TabletPropertyDescriptionCollection, add X and Y
Dim tpDescCollection As TabletPropertyDescriptionCollection = New TabletPropertyDescriptionCollection()
tpDescCollection.Add(New TabletPropertyDescription(PacketProperty.X, MetricX))
tpDescCollection.Add(New TabletPropertyDescription(PacketProperty.Y, MetricY))
' see if the default tablet supports pressure
Dim supportPressure As Boolean = allTablets.DefaultTablet.IsPacketPropertySupported(PacketProperty.NormalPressure)
' if so, add NormalPressure to TabletPropertyDescriptionCollection
If supportPressure Then
Dim MetricP As TabletPropertyMetrics = allTablets.DefaultTablet.GetPropertyMetrics(PacketProperty.NormalPressure)
tpDescCollection.Add(New TabletPropertyDescription(PacketProperty.NormalPressure, MetricP))
End If
' init random number generator
Dim R As Random = New Random()
' init total PacketCount, slotPerPacket and packet data array
Const PACKET_COUNT As Integer = 250
Dim slotPerPacket As Integer = tpDescCollection.Count
Dim pData((PACKET_COUNT * slotPerPacket) - 1) As Integer
' assign packet values
For k As Integer = 0 To PACKET_COUNT - 1
' assign X - X will increment by 106
pData(k * slotPerPacket) = (k * 106)
' assign Y - Y will be 6000 +- 1500
pData((k * slotPerPacket) + 1) = 6000 + R.Next(-1500, 1500)
' assign Pressure if supported, 25-255
If (supportPressure) Then
pData((k * slotPerPacket) + 2) = R.Next(25, 255)
End If
next
' create the Stroke
mInkOverlay.Ink.CreateStroke(pData, tpDescCollection)
mInkOverlay.AttachedControl.Invalidate()
Tablets allTablets = new Tablets();
// get the property metrics for X and Y
TabletPropertyMetrics MetricX = allTablets.DefaultTablet.GetPropertyMetrics(PacketProperty.X);
TabletPropertyMetrics MetricY = allTablets.DefaultTablet.GetPropertyMetrics(PacketProperty.Y);
// create the TabletPropertyDescriptionCollection, add X and Y
TabletPropertyDescriptionCollection tpDescCollection = new TabletPropertyDescriptionCollection();
tpDescCollection.Add(new TabletPropertyDescription(PacketProperty.X, MetricX));
tpDescCollection.Add(new TabletPropertyDescription(PacketProperty.Y, MetricY));
// see if the default tablet supports pressure
bool supportPressure = allTablets.DefaultTablet.IsPacketPropertySupported(PacketProperty.NormalPressure);
// if so, add NormalPressure to TabletPropertyDescriptionCollection
if (supportPressure)
{
TabletPropertyMetrics MetricP = allTablets.DefaultTablet.GetPropertyMetrics(PacketProperty.NormalPressure);
tpDescCollection.Add(new TabletPropertyDescription(PacketProperty.NormalPressure, MetricP));
}
// init random number generator
Random R = new Random();
// init total PacketCount, slotPerPacket and packet data array
const int PACKET_COUNT = 250;
int slotPerPacket = tpDescCollection.Count;
int[] pData = new int[PACKET_COUNT*slotPerPacket];
// assign packet values
for (int k = 0; k < PACKET_COUNT; k++)
{
// assign X - X will increment by 106
pData[k * slotPerPacket] = (k * 106);
// assign Y - Y will be 6000 +- 1500
pData[(k * slotPerPacket) + 1] = 6000 + R.Next(-1500, 1500);
// assign Pressure if supported, 25-255
if (supportPressure)
{
pData[(k * slotPerPacket) + 2] = R.Next(25, 255);
}
}
// create the Stroke
mInkOverlay.Ink.CreateStroke(pData, tpDescCollection);
mInkOverlay.AttachedControl.Invalidate();
Platforms
Windows 7, Windows Vista, Windows Server 2008 R2, Windows Server 2008
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information
.NET Framework
Supported in: 3.0
See Also
Reference
TabletPropertyDescriptionCollection.InkToDeviceScaleX