Módulos

La API de Ink está modularizada, por lo que puedes usar solo lo que necesitas.

Brazadas

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. InProgressStroke is used to render partial strokes with low latency and to build the final Stroke once input is complete, after which the object can be reused. `InProgressStroke is used by InProgressStrokesView.
  • Stroke: An immutable representation of a finalized stroke with fixed geometry. Each Stroke has an ImmutableStrokeInputBatch (input points), a Brush (style), and a PartitionedMesh (geometric shape). You can store, manipulate, and render strokes within your application.

Geometría

几何图形模块支持对基本形状(使用 Box 和 Vec 等专用类)以及任意形状(使用 PartitionedMesh)进行几何运算,包括相交检测和转换。 PartitionedMesh 还可以保存其他数据以支持渲染。

Pincel

The brush module defines the style of strokes. It consists of two main parts:

  • Brush: Specifies the style of a stroke including base color, base size, and BrushFamily. BrushFamily is analogous to a font family, it defines a stroke's style. For example, a BrushFamily can represent a specific style of marker or highlighter, allowing strokes with different sizes and colors to share that style.
  • StockBrushes: Provides factory functions for creating ready-to-use BrushFamily instances.

Autoría

借助 Authoring 模块,您可以捕获用户指针输入,并将其实时呈现为屏幕上的低延迟笔画。它提供了一个 InProgressStrokesView,用于处理运动事件并显示绘制的笔画。

笔画完成后,视图会通过注册的回调 (InProgressStrokesFinishedListener) 通知客户端应用。通过该回调,应用可以检索已完成的笔画以进行渲染或存储。

Renderización

El módulo de renderización te ayuda a dibujar trazos de tinta en un Canvas de Android. Proporciona CanvasStrokeRenderer para Compose y ViewStrokeRenderer para diseños basados en vistas. Estos renderizadores están diseñados para un renderizado de alto rendimiento y ayudan a ofrecer imágenes de alta calidad, incluido el suavizado.

Para renderizar trazos, llama al método create() para obtener una instancia de CanvasStrokeRenderer. Luego, llama al método draw() para renderizar trazos terminados (Stroke) o en curso (InProgressStroke) en un objeto Canvas.

Puedes transformar el lienzo cuando dibujas un trazo. Algunos ejemplos incluyen el desplazamiento horizontal, el zoom y la rotación. Para renderizar el trazo correctamente, también debes pasar la transformación canvas a CanvasStrokeRenderer.draw.

Para evitar hacer un seguimiento de la transformación canvas por separado, usa ViewStrokeRenderer.

Almacenamiento

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.