โมดูล

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. 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 the InProgressStrokes composable.
  • 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.

เรขาคณิต

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 จะกำหนดสไตล์ของเส้น โดยมีส่วนประกอบหลัก 2 ส่วน ได้แก่

  • Brush: ระบุรูปแบบของเส้นขีด รวมถึง สีพื้นฐาน ขนาดพื้นฐาน และ BrushFamily BrushFamily มีลักษณะคล้ายกับชุดแบบอักษร โดยจะกำหนดสไตล์ของเส้นขีด เช่น BrushFamily สามารถแสดงถึงรูปแบบเฉพาะของเครื่องหมายหรือ ไฮไลต์ ซึ่งช่วยให้เส้นที่มีขนาดและสีต่างกันแชร์รูปแบบนั้นได้
  • StockBrushes: มีฟังก์ชันจากโรงงานสำหรับ สร้างอินสแตนซ์ BrushFamily ที่พร้อมใช้งาน

การเขียน

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.