Ink API เป็นแบบแยกส่วน คุณจึงใช้ได้เฉพาะสิ่งที่ต้องการ
สโตรก
โมดูลเส้นเป็นรากฐานของ Ink API ประเภทข้อมูลหลัก ภายในโมดูลนี้ ได้แก่
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, 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.
การแสดงภาพ
โมดูลการแสดงผลช่วยให้การวาดเส้นหมึกลงใน Android
Canvas ง่ายขึ้น
โดยมี CanvasStrokeRenderer สำหรับ Compose และ
ViewStrokeRenderer สำหรับเลย์เอาต์ที่อิงตาม View โดย
โปรแกรมแสดงผลเหล่านี้จะเพิ่มประสิทธิภาพการแสดงผลและช่วยแสดงภาพคุณภาพสูง
รวมถึงการป้องกันรอยหยัก
หากต้องการแสดงผลลายเส้น ให้เรียกใช้เมธอด create() เพื่อรับอินสแตนซ์ CanvasStrokeRenderer จากนั้นเรียกใช้เมธอด draw() เพื่อ
แสดงผลลายเส้นที่เสร็จแล้ว (Stroke) หรือลายเส้นที่กำลังดำเนินการ
(InProgressStroke) บน Canvas
คุณสามารถเปลี่ยนรูปผืนผ้าใบได้เมื่อวาดเส้น ตัวอย่างเช่น การแพน
การซูม และการหมุน หากต้องการแสดงผลเส้นขีดอย่างถูกต้อง คุณต้องส่งcanvas transform ไปยัง 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.