Ink API 已模块化,因此您可以仅使用所需的功能。
笔画
The strokes module serves as the foundation of the Ink API. Key data types within this module are:
StrokeInputBatch: Represents a series of pointer inputs, including their position, timestamp, and optionally pressure, tilt, and orientation.InProgressStroke: Represents a stroke that is actively being drawn.InProgressStrokeis used to render partial strokes with low latency and to build the finalStrokeonce input is complete, after which the object can be reused. `InProgressStrokeis used byInProgressStrokesView.Stroke: An immutable representation of a finalized stroke with fixed geometry. EachStrokehas anImmutableStrokeInputBatch(input points), aBrush(style), and aPartitionedMesh(geometric shape). You can store, manipulate, and render strokes within your application.
几何体
The Geometry module supports geometric operations on primitive shapes (using dedicated classes like Box and Vec), as well as arbitrary shapes (using PartitionedMesh), including intersection detection and transformation. PartitionedMesh can also hold additional data to support rendering.
笔刷
brush 模块定义了笔画的样式。它包含两个主要部分:
Brush:指定笔画的样式,包括基准颜色、基准大小和BrushFamily。BrushFamily类似于字体系列,用于定义笔画的样式。例如,BrushFamily可以表示某种特定样式的标记或荧光笔,从而使不同大小和颜色的笔画共享该样式。StockBrushes:提供用于创建即用型BrushFamily实例的工厂函数。
编写
The Authoring module lets you capture user pointer input and render it as low-latency strokes on the screen in real time. It provides an InProgressStrokesView, which processes motion events and displays the strokes as they are drawn.
Once a stroke is completed, the view notifies the client application by means
of a registered callback
(InProgressStrokesFinishedListener). The callback lets
the application retrieve the finished stroke for rendering or storage.
渲染
渲染模块可帮助您在 Android Canvas 上绘制墨水笔画。它为 Compose 提供 CanvasStrokeRenderer,为基于视图的布局提供 ViewStrokeRenderer。这些渲染器专为高性能渲染而设计,有助于提供高质量的视觉效果,包括抗锯齿。
如需渲染笔画,请调用 create() 方法以获取 CanvasStrokeRenderer 实例。然后,调用 draw() 方法,将已完成 (Stroke) 或正在进行 (InProgressStroke) 的笔画渲染到 Canvas 上。
您可以在绘制笔画时转换画布。例如平移、缩放和旋转。为了正确渲染描边,您还必须将 canvas 转换传递给 CanvasStrokeRenderer.draw。
为避免单独跟踪 canvas 转换,请改用 ViewStrokeRenderer。
存储
The storage module provides utilities for
efficiently serializing and deserializing stroke data, primarily focusing
on StrokeInputBatch.
The module uses protocol buffers and optimized delta compression techniques, resulting in significant storage savings compared to naive methods.
The storage module simplifies saving, loading, and sharing strokes.