Brush API
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
API ของ Brush
มีเครื่องมือในการกำหนดสไตล์ภาพเส้นวาด คุณสามารถสร้างแปรงที่มีสี ขนาด และแปรงสำหรับครอบครัวเพื่อให้ได้ลุคต่างๆ
สร้างแปรง
หากต้องการสร้างแปรง ให้ใช้วิธีการจากโรงงานของ Brush
เช่น คลาส createWithColorIntArgb()
วิธีการจากโรงงานจะให้คุณตั้งค่าคุณสมบัติต่อไปนี้
- ตระกูล: รูปแบบของแปรง ซึ่งคล้ายกับแบบตัวพิมพ์หรือแบบอักษรในข้อความ
ดู
StockBrushes
สำหรับ
ค่า BrushFamily
ที่ใช้ได้
- color: สีของแปรง คุณตั้งค่าสีได้โดยใช้
ColorLong
หรือ ColorInt
- ขนาด: ความหนาโดยรวมของเส้นที่วาดด้วยแปรง
- epsilon: ระยะทางที่สั้นที่สุดที่ควรพิจารณาว่าจุด 2 จุดมีความแตกต่างกันในลักษณะที่มองเห็นได้เพื่อวัตถุประสงค์ด้านเรขาคณิตของการสร้างเส้น อัตราส่วนของ EPsilon และจุดของเส้นโครงร่างจะควบคุมจำนวนเส้นโครงร่างที่ซูมเข้าได้
โดยไม่มีอาร์ติแฟกต์ที่จำเป็นต้องใช้หน่วยความจำ จุดเริ่มต้นที่ดีสำหรับหน่วยเส้นโครงร่างคือ 1 พิกเซล และจุดเริ่มต้นที่ดีสำหรับ epsilon คือ 0.1 ค่า epsilon ที่สูงขึ้นจะใช้หน่วยความจําน้อยลง แต่คุณจะซูมได้น้อยลงก่อนที่ข้อบกพร่องรูปสามเหลี่ยมจะปรากฏขึ้น ให้ทดสอบเพื่อหาค่าที่เหมาะสมกับกรณีการใช้งานของคุณ
val brush = Brush.createWithColorIntArgb(
family = StockBrushes.pressurePenLatest,
colorIntArgb = Color.Black.toArgb(),
size = 5F,
epsilon = 0.1F
)
แก้ไขพร็อพเพอร์ตี้ของแปรง
คุณจะสร้างสำเนาแปรงที่มีอยู่ได้โดยใช้เมธอด copy()
วิธีนี้ช่วยให้คุณสามารถเปลี่ยนคุณสมบัติของแปรงได้
val redBrush = Brush.createWithColorIntArgb(
family = StockBrushes.pressurePenLatest,
colorIntArgb = Color.RED.toArgb(),
size = 5F,
epsilon = 0.1F
)
val blueBrush = redBrush.copy(colorIntArgb = Color.BLUE.toArgb())
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-07-27 UTC"],[],[],null,["# Brush APIs\n\nThe [`Brush`](/reference/kotlin/androidx/ink/brush/Brush) APIs provide you with\nthe tools to define the visual style of your strokes. You can create brushes\nwith different colors, sizes, and families to achieve a variety of looks.\n\nCreate a brush\n--------------\n\nTo create a brush, use the [`Brush`](/reference/kotlin/androidx/ink/brush/Brush)\nfactory methods such as\n[`createWithColorIntArgb()`](/reference/kotlin/androidx/ink/brush/Brush#createWithColorIntArgb(androidx.ink.brush.BrushFamily,kotlin.Int,kotlin.Float,kotlin.Float))\nclass. The factory methods let you set the following properties:\n\n- **family** : The style of the brush, analogous to a typeface or font in text. See [`StockBrushes`](/reference/kotlin/androidx/ink/brush/StockBrushes) for available [`BrushFamily`](/reference/kotlin/androidx/ink/brush/BrushFamily) values.\n- **color** : The color of the brush. You can set the color using a [`ColorLong`](/reference/kotlin/androidx/annotation/ColorLong) or [`ColorInt`](/reference/androidx/annotation/ColorInt).\n- **size**: The overall thickness of strokes created with the brush.\n- **epsilon**: The smallest distance for which two points should be considered visually distinct for stroke generation geometry purposes. The ratio of epsilon and stroke points control how much a stroke can be zoomed in without artifacts at the cost of memory. A good starting point for stroke units is 1px, and a good starting point for epsilon is 0.1. Higher epsilon values use less memory but allow for less zoom before triangle artifacts appear; experiment to find the right value for your use case.\n\n val brush = Brush.createWithColorIntArgb(\n family = StockBrushes.pressurePenLatest,\n colorIntArgb = Color.Black.toArgb(),\n size = 5F,\n epsilon = 0.1F\n )\n\nModify brush properties\n-----------------------\n\nYou can create a copy of an existing brush using the\n[`copy()`](/reference/kotlin/androidx/ink/brush/Brush#copy(androidx.ink.brush.BrushFamily,kotlin.Float,kotlin.Float))\nmethod. This method lets you change any of the brush's properties. \n\n val redBrush = Brush.createWithColorIntArgb(\n family = StockBrushes.pressurePenLatest,\n colorIntArgb = Color.RED.toArgb(),\n size = 5F,\n epsilon = 0.1F\n )\n\n val blueBrush = redBrush.copy(colorIntArgb = Color.BLUE.toArgb())"]]