Модули

API Ink имеет модульную структуру, поэтому вы можете использовать только то, что вам необходимо.

Инсульты

Модуль «Штрихи» служит основой API Ink. Ключевые типы данных в этом модуле:

  • StrokeInputBatch : Представляет собой последовательность входных данных указателя, включая его положение, метку времени, а также, при необходимости, давление, наклон и ориентацию.
  • InProgressStroke : Представляет собой контур, который активно рисуется. InProgressStroke используется для рендеринга частичных контуров с низкой задержкой и для построения окончательного Stroke после завершения ввода, после чего объект можно использовать повторно.InProgressStroke используется в компоненте InProgressStrokes .
  • Stroke : Неизменяемое представление окончательного варианта штриха с фиксированной геометрией. Каждый Stroke имеет ImmutableStrokeInputBatch (входные точки), Brush (стиль) и PartitionedMesh (геометрическая форма). Вы можете хранить, изменять и отображать штрихи в своем приложении.

Геометрия

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.

Щетка

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.

Создание контента

The Compose Authoring module lets you capture user touch input and render it as low-latency strokes on the screen in real time. This is achieved through the InProgressStrokes composable, which processes motion events and displays the strokes as they are drawn.

Once a stroke is completed, the composable notifies the client application using an InProgressStrokesFinishedListener callback. This allows the application to retrieve the finished strokes for rendering or storage.

In Compose, InProgressStrokes takes this callback in the onStrokesFinished parameter. Pass the finished strokes to another composable to commit them to the screen using the rendering module.

Визуализация

Модуль Rendering упрощает рисование штрихов чернилами на Android Canvas . Он предоставляет CanvasStrokeRenderer для Compose и ViewStrokeRenderer для макетов на основе представлений. Эти рендереры оптимизируют производительность рендеринга и помогают обеспечить высококачественное отображение, включая сглаживание.

Для отрисовки штрихов вызовите метод create() , чтобы получить экземпляр CanvasStrokeRenderer , а затем вызовите метод draw() , чтобы отрисовать на Canvas либо завершенные ( Stroke ), либо незавершенные ( InProgressStroke ) штрихи.

При рисовании обводки можно изменять холст. Например, можно перемещать, масштабировать и вращать изображение. Для корректного отображения обводки необходимо также передать преобразование 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.