模組
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Ink API 已模組化,因此您可以只使用所需的功能。
筆觸
Strokes 模組是 Ink 程式庫的基礎,提供主要 API 介面,並包含與程式庫互動的核心資料類型。本單元的主要資料類型包括:
幾何學
「Geometry」(幾何圖形) 模組
提供一系列適用於基本和複雜模型的幾何圖形基元
以及交叉偵測和轉換的作業。
這些基本元素可與 Ink 筆劃完美整合,讓您打造整筆劃橡皮擦和選取框選工具等功能。
如果 Box
和
Vec
主要便於協助
幾何運算
PartitionedMesh
可能會
也包含轉譯特定資料
筆刷
Brush 模組可做為宣告式設定,用於建立和算繪筆劃,運作方式類似文字字型。A 罩杯
Brush
物件含有
屬性:
- 顏色:可以是純色,也可以是疊加特效和紋理的基礎。
- 大小:可固定或做為動態大小調整項的基礎。
- Family:類似於文字字體,family 會定義筆劃的整體樣式。
- Epsilon:控制筆劃向量幾何圖形的細節等級
代表最小的視覺差異
epsilon
屬性會播放
是定義座標系統精確度的重要角色更多指引
選擇適當的 Epsilon 值
BrushFamily
會用來
這個強大的設定可建立表達式的筆觸,無需深入瞭解
複雜的幾何或轉譯程式碼這個程式庫提供一組預先定義的 StockBrushes
,包括壓力感應筆、螢光筆和標記。
編寫
Authoring
模組可讓開發人員擷取使用者觸控輸入內容,並算繪為
螢幕上即時的低延遲筆劃系統會透過
InProgressStrokesView
類別,
處理動作事件,並在繪製筆觸時以視覺化方式呈現。
筆劃完成後,模組會使用 onStrokesFinished()
回呼通知用戶端應用程式 InProgressStrokesFinishedListener
。回呼可讓應用程式擷取完成的筆觸資料,用於算繪或儲存。
轉譯
轉譯模組可簡化在 Android Canvas
上繪製墨水筆觸的程序。單元
提供了 CanvasStrokeRenderer
適用於 Compose 和
ViewStrokeRenderer
用於以檢視畫面為基礎的版面配置,這兩種做法都能改善算繪效能,並確保
圖像化,包括消除鋸齒等
如要將筆觸轉譯至畫布,請取得
CanvasStrokeRenderer
使用
create()
方法。接著,使用
draw()
方法來轉譯已完成或處理中的筆觸。
畫到畫布上
在繪製筆劃時,可將畫布轉換 (平移、縮放或旋轉),但為了確保筆劃在螢幕上繪製時看起來最美觀,您必須將套用至畫布的轉換傳遞至 CanvasStrokeRenderer#draw()
。為避免產生個別追蹤記錄,請使用
ViewStrokeRenderer
。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Modules\n\nThe [Ink API](/jetpack/androidx/releases/ink#1.0.0-alpha01) is modularized, so you can use only what you need.\n\nStrokes\n-------\n\nThe [Strokes](/reference/kotlin/androidx/ink/strokes/package-summary) module serves as the foundation of the Ink library, offering the\nprimary API interface and containing the core data types for interacting with\nthe library. Key data types within this module include:\n\n- [**`StrokeInputBatch`**](/reference/kotlin/androidx/ink/strokes/StrokeInputBatch): Represents a series of pointer inputs, encompassing position, timestamp, and optionally pressure, tilt, and orientation. This data can be utilized with the [`Stroke`](/reference/kotlin/androidx/ink/strokes/Stroke) or [`InProgressStroke`](/reference/kotlin/androidx/ink/strokes/InProgressStroke) classes, and is the type that would provide the inputs for a handwriting recognition library.\n- [**`Stroke`**](/reference/kotlin/androidx/ink/strokes/Stroke): An immutable representation of a finalized stroke with fixed geometry. Stroke comprises an [`ImmutableStrokeInputBatch`](/reference/kotlin/androidx/ink/strokes/ImmutableStrokeInputBatch) (input points), a [`Brush`](/reference/kotlin/androidx/ink/brush/Brush) (styling), and a [`PartitionedMesh`](/reference/kotlin/androidx/ink/geometry/PartitionedMesh) (geometric shape). Strokes can be stored, manipulated, and rendered within your application.\n- [**`InProgressStroke`**](/reference/kotlin/androidx/ink/strokes/InProgressStroke): A mutable counterpart to [`Stroke`](/reference/kotlin/androidx/ink/strokes/Stroke) designed for incremental input handling and real-time rendering during the drawing process. While often used indirectly through [`InProgressStrokesView`](/reference/kotlin/androidx/ink/authoring/InProgressStrokesView), [`InProgressStroke`](/reference/kotlin/androidx/ink/strokes/InProgressStroke) can be leveraged directly for advanced customization.\n\nGeometry\n--------\n\nThe [Geometry](/reference/kotlin/androidx/ink/geometry/package-summary) module\nprovides a suite of geometry primitives for both basic and complex\nshapes along with operations for intersection detection and transformations.\nThese primitives seamlessly integrate with Ink strokes, empowering you to build\nfeatures like whole-stroke erasers and marquee selection tools.\n\nWhile classes like [`Box`](/reference/kotlin/androidx/ink/geometry/Box) and\n[`Vec`](/reference/kotlin/androidx/ink/geometry/Vec) primarily facilitate\ngeometric operations,\n[`PartitionedMesh`](/reference/kotlin/androidx/ink/geometry/PartitionedMesh) may\nalso include rendering-specific data.\n\nBrush\n-----\n\nThe [Brush](/reference/kotlin/androidx/ink/brush/package-summary) module\nacts as a declarative configuration for stroke creation and rendering,\nfunctioning similarly to a text font. A\n[`Brush`](/reference/kotlin/androidx/ink/brush/Brush) object ha the\nfollowing properties:\n\n- **Color**: Can be a solid color or the foundation for layered effects and textures.\n- **Size**: Can be fixed or serve as a base for dynamic size adjustments.\n- **Family**: Analogous to a text typeface, family defines the stroke's overall style.\n- **Epsilon**: Controls the level of detail in the stroke's vector geometry, representing the smallest unit of visual distinction.\n\nThe [`epsilon`](/reference/kotlin/androidx/ink/brush/Brush#epsilon()) property plays a\ncrucial role in defining the precision of your coordinate system. More guidance\nis provided in the [Brush APIs](?tab=t.0#heading=h.j5tn81xa7fph) section on how\nto choose an appropriate epsilon value.\n\nThe [`BrushFamily`](/reference/kotlin/androidx/ink/brush/BrushFamily) serves as\na powerful configuration for creating expressive strokes without delving into\ncomplex geometry or rendering code. The library provides a set of predefined\n[`StockBrushes`](/reference/kotlin/androidx/ink/brush/StockBrushes), including a\npressure-sensitive pen, highlighter, and marker.\n\nAuthoring\n---------\n\nThe [`Authoring`](/reference/kotlin/androidx/ink/authoring/package-summary)\nmodule enables developers to capture user touch input and render it as\nlow-latency strokes on the screen in real-time. This is achieved through the\n[`InProgressStrokesView`](/reference/kotlin/androidx/ink/authoring/InProgressStrokesView) class,\nwhich processes motion events and visualizes the strokes as they're drawn.\n\nOnce a stroke is completed, the module notifies the client application using the\n[`onStrokesFinished()`](/reference/kotlin/androidx/ink/authoring/InProgressStrokesFinishedListener#onStrokesFinished(kotlin.collections.Map))\ncallback of\n[`InProgressStrokesFinishedListener`](/reference/kotlin/androidx/ink/authoring/InProgressStrokesFinishedListener).\nThe callback allows the application to retrieve the\nfinished stroke data for rendering or storage.\n\nRendering\n---------\n\nThe Rendering module simplifies the process of drawing ink strokes onto an\nAndroid [`Canvas`](/reference/kotlin/android/graphics/Canvas). The module\nprovides a [`CanvasStrokeRenderer`](/reference/androidx/ink/rendering/android/canvas/CanvasStrokeRenderer)\nfor Compose and\n[`ViewStrokeRenderer`](/reference/androidx/ink/rendering/android/view/ViewStrokeRenderer)\nfor view-based layouts, both of which optimize rendering performance and ensure\nhigh-quality visuals, including anti-aliasing.\n\nTo render strokes to a canvas, obtain a\n[`CanvasStrokeRenderer`](/reference/kotlin/androidx/ink/rendering/android/canvas/CanvasStrokeRenderer)\ninstance using the\n[`create()`](/reference/kotlin/androidx/ink/rendering/android/canvas/CanvasStrokeRenderer#create())\nmethod. Then, use the\n[`draw()`](/reference/kotlin/androidx/ink/rendering/android/canvas/CanvasStrokeRenderer#draw(android.graphics.Canvas,androidx.ink.strokes.InProgressStroke,androidx.ink.geometry.AffineTransform))\nmethod to render either finished or in-progress strokes.\nstrokes onto a canvas.\n\nThe canvas can be transformed (panned, zoomed, or rotated) as part of drawing the\nstroke, but to make sure the stroke looks its best drawn on screen, the\ntransform applied to the canvas must also be passed to\n`CanvasStrokeRenderer#draw()`.\nTo avoid needing to keep track of this separately, use\n[`ViewStrokeRenderer`](/reference/kotlin/androidx/ink/rendering/android/view/ViewStrokeRenderer)\ninstead."]]