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 by theInProgressStrokescomposable.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
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, andBrushFamily.BrushFamilyis analogous to a font family, it defines a stroke's style. For example, aBrushFamilycan 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-useBrushFamilyinstances.
編寫
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 上繪製墨水筆觸。當中提供 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.