Ink.CreateStroke 方法 (array<Int32[], TabletPropertyDescriptionCollection)
根据数据包数据创建 Stroke 对象。
命名空间: Microsoft.Ink
程序集: Microsoft.Ink(在 Microsoft.Ink.dll 中)
语法
声明
Public Function CreateStroke ( _
packetData As Integer(), _
tabletPropertyDescriptionCollection As TabletPropertyDescriptionCollection _
) As Stroke
用法
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 Stroke CreateStroke(
int[] packetData,
TabletPropertyDescriptionCollection tabletPropertyDescriptionCollection
)
public function CreateStroke(
packetData : int[],
tabletPropertyDescriptionCollection : TabletPropertyDescriptionCollection
) : Stroke
参数
- packetData
类型:array<System.Int32[]
用于组成 Stroke 对象的数据包数据数组。
- tabletPropertyDescriptionCollection
类型:Microsoft.Ink.TabletPropertyDescriptionCollection
描述 packetData 数组中具有哪些属性的 TabletPropertyDescriptionCollection 集合。
返回值
类型:Microsoft.Ink.Stroke
新创建的笔画。
新创建的 Stroke 对象。
备注
packetData 参数中的数组的大小必须能被 tabletPropertyDescriptionCollection 参数的大小整除。
备注
packetData 参数中的每个数据包的前两个元素都必须依次为 X 和 Y。如果未在每个数据包的第一和第二个位置分别指定 X 和 Y,则会引发 ArgumentException。
示例
在此示例中,根据随机数据包数据创建表示不规则正弦波的笔画。首先,依次获取 PacketPropertyX 和 Y 的 TabletPropertyMetrics,以便利用这些 PacketProperty 类型的 TabletPropertyDescription 对象初始化 TabletPropertyDescriptionCollection。如果默认 Tablet 支持 NormalPressure,则也会将它添加到集合。然后,创建实际数据包数据,并将这些数据传递给 CreateStroke 方法。
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();
平台
Windows Vista
.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。
版本信息
.NET Framework
受以下版本支持:3.0
另请参见
参考
TabletPropertyDescriptionCollection.InkToDeviceScaleX