首页
社区
课程
招聘
[原创]书写不再“断片”!Pen Kit报点预测丝滑如真笔
发表于: 2025-8-30 11:20 298

[原创]书写不再“断片”!Pen Kit报点预测丝滑如真笔

2025-8-30 11:20
298

传统手写场景中,用户常因笔尖滞后、轨迹抖动等问题导致书写体验割裂,而开发者则面临跨设备适配复杂、算法优化成本高等痛点。

HarmonyOS SDK手写笔服务(Pen Kit)提供报点预测能力,根据书写轨迹预测报点提前进行绘制,提高手写跟手性,手写套件已默认开启报点预测,您也可以在应用中单独集成报点预测功能。

在应用的自定义界面中,获取到界面的触摸事件,通过调用报点预测的接口,可以得到预测的下一个报点的位置信息。

应用场景

教育创作:提升涂鸦场景的跟手性。

开发步骤

  1. 导入相关模块。

import { PointPredictor } from '@kit.Penkit';

  1. 获取当前界面的触摸事件信息,调用接口计算预测点信息。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
@Entry
@Component
struct PointPredictorDemo {
  @State actualXCoordinate: number = 0
  @State actualYCoordinate: number = 0
  @State predictorXCoordinate: Dimension = 0
  @State predictorYCoordinate: Dimension = 0
  pointPredictor: PointPredictor = new PointPredictor();
 
  aboutToAppear() {
    console.info('getPredictionPoint aboutToAppear')
  }
 
  aboutToDisappear() {
    console.info('getPredictionPoint aboutToDisappear')
  }
 
  build() {
    Stack({ alignContent: Alignment.TopEnd }) {
      this.Canvas() // Canvas.
    }.height('100%').width('100%')
  }
 
  // 画布
  @Builder
  Canvas() {
    Column() {
      Text("实际点坐标: X: " + this.actualXCoordinate + " Y: " + this.actualYCoordinate).textAlign(TextAlign.Start)
      Text("预测点坐标: X: " + this.predictorXCoordinate + " Y: " + this.predictorYCoordinate)
        .textAlign(TextAlign.Start)
    }.position({ x: 0, y: 0 })
    .alignItems(HorizontalAlign.Start)
 
    Stack()
      .width('100%')
      .height('100%')
      .onTouch((event: TouchEvent) => {
        switch (event.type) {
          case TouchType.Down: // Create a drawing path when the screen is touched.
            break;
          case TouchType.Move: // Use the prediction algorithm to perform prediction and obtain the prediction point.
            let point = this.pointPredictor?.getPredictionPoint(event)
            this.actualXCoordinate = event.touches[0]?.x
            this.actualYCoordinate = event.touches[0]?.y
            this.predictorXCoordinate = point?.x
            this.predictorYCoordinate = point?.y
            console.info("pointPredictor 实际点坐标 x:" + event.touches[0]?.x + " y:" + event.touches[0]?.y)
            console.info("pointPredictor 预测点坐标 x:" + point?.x + "  y:" + point?.y)
            break;
          case TouchType.Up:
            break;
        }
      })
  }
}

了解更多详情>>

访问手写笔服务官网

获取报点预测开发指导文档


[培训]Windows内核深度攻防:从Hook技术到Rootkit实战!

最后于 2025-8-30 11:29 被HarmonyOS SDK编辑 ,原因:
收藏
免费 0
支持
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回