Module

Die Ink API ist modularisiert, sodass Sie nur die Funktionen verwenden können, die Sie benötigen.

Schläge

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.

Geometrie

Das Modul Geometry unterstützt geometrische Operationen für primitive Formen (mit speziellen Klassen wie Box und Vec) sowie beliebige Formen (mit PartitionedMesh), einschließlich der Erkennung von Überschneidungen und Transformationen. PartitionedMesh kann auch zusätzliche Daten für das Rendern enthalten.

Pinsel

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.

Autorentool

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.

Rendering

Mit dem Rendering-Modul können Sie Tuschestriche auf einem Android-Canvas zeichnen. Es bietet CanvasStrokeRenderer für Compose und ViewStrokeRenderer für auf Views basierende Layouts. Diese Renderer sind für das leistungsstarke Rendern konzipiert und tragen dazu bei, hochwertige Grafiken zu liefern, einschließlich Antialiasing.

Rufen Sie zum Rendern von Strichen die Methode create() auf, um eine CanvasStrokeRenderer-Instanz zu erhalten. Rufen Sie dann die Methode draw() auf, um entweder fertige (Stroke) oder laufende (InProgressStroke) Striche auf einem Canvas zu rendern.

Sie können die Arbeitsfläche transformieren, während Sie einen Strich zeichnen. Beispiele hierfür sind Schwenken, Zoomen und Drehen. Damit der Strich richtig gerendert wird, müssen Sie auch die canvas-Transformation an CanvasStrokeRenderer.draw übergeben.

Wenn Sie die canvas-Transformation nicht separat erfassen möchten, verwenden Sie stattdessen ViewStrokeRenderer.

Speicher

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.