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.
هندسه
ماژول Geometry از عملیات هندسی روی اشکال اولیه (با استفاده از کلاسهای اختصاصی مانند Box و Vec ) و همچنین اشکال دلخواه (با استفاده از PartitionedMesh ) از جمله تشخیص تقاطع و تبدیل پشتیبانی میکند. PartitionedMesh همچنین میتواند دادههای اضافی را برای پشتیبانی از رندرینگ در خود نگه دارد.
برس
ماژول brush سبک خطوط را تعریف میکند و از دو بخش اصلی تشکیل شده است:
-
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.
رندرینگ
ماژول Rendering، ترسیم خطوط جوهر روی Canvas اندروید را ساده میکند. این CanvasStrokeRenderer را برای Compose و ViewStrokeRenderer را برای طرحبندیهای مبتنی بر نما فراهم میکند. این رندرکنندهها عملکرد رندر را بهینه کرده و به ارائه تصاویر با کیفیت بالا، از جمله ضد لبهسازی، کمک میکنند.
برای رندر کردن strokeها، متد create() را برای دریافت یک نمونه CanvasStrokeRenderer فراخوانی کنید، و سپس متد draw() را برای رندر strokeهای تکمیلشده ( Stroke ) یا در حال انجام ( InProgressStroke ) روی یک Canvas فراخوانی کنید.
شما میتوانید هنگام رسم یک stroke، بوم را تغییر شکل دهید. مثالها شامل panning، zooming و rotation میشود. برای رندر صحیح stroke، باید transform canvas را به CanvasStrokeRenderer.draw نیز ارسال کنید.
برای جلوگیری از ردیابی جداگانهی تبدیل canvas ، به جای آن ViewStrokeRenderer استفاده کنید.
ذخیرهسازی
ماژول ذخیرهسازی ، ابزارهایی را برای سریالسازی و از سریالسازی خارج کردن کارآمد دادههای stroke ارائه میدهد که عمدتاً بر StrokeInputBatch تمرکز دارد.
این ماژول از بافرهای پروتکل و تکنیکهای فشردهسازی دلتا بهینهشده استفاده میکند که منجر به صرفهجویی قابل توجه در ذخیرهسازی در مقایسه با روشهای ساده میشود.
ماژول ذخیرهسازی، ذخیره، بارگذاری و اشتراکگذاری strokeها را ساده میکند.