In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to use Androi native drawing tool Paint, which is very detailed and has certain reference value. Friends who are interested must finish reading it!
Foreword:
Drawing patterns in daily life requires paper and pen, and android provides similar tools Canvas and Paint, corresponding to canvas and brush, respectively.
The Paint class holds the style and color information about how to draw geometries, text and bitmaps.
Paint has style and color information for drawing geometry, text, and pictures.
The Canvas class holds the "draw" calls. To draw something, you need 4 basic components: A Bitmap to hold the pixels, a Canvas to host the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect, Path, text, Bitmap), and a paint (to describe the colors and styles for the drawing).
Canvas has the right to request a drawing. To complete the drawing, you need four basic elements: a Bitmap to save pixels, a canvas that can call the draw method, a description of the content to be drawn, and a brush. With these four elements, you can draw it to a bitmap and render it to the screen.
1. Brief introduction
Paint provides three initialization methods:
Paint () Paint (int flag) Paint (Paint paint) 2. Basic properties use 2.1 setAlpha transparency
SetAlpha (int a) setting range 0" 255 "
2.2 setStyle fill pattern
Fill patterns represent the selection of sketch lines and fills:
Paint.Style.FILLPaint.Style.FILL_AND_STROKEPaint.Style.STROKE
2.3 colors, fonts, alignment, anti-aliasing
SetColor,setARGB sets the color, sets the brush color
The setARGB () parameter ranges from 0 to 255.
SetAntiAlias (boolean) anti-aliasing makes the boundaries smoother (some screens have low resolution, resulting in large pixels, the drawing boundary may feel grainy, and turning on the anti-aliasing boundary will reduce the graininess).
SetTextSize (float textSize) font size, in px, if it is dp, you should pay attention to the conversion.
SetTextAlign (Paint.Align.RIGHT) sets the font alignment, which is based on the starting point, as shown in the following example.
MTextPaint.setTextAlign (Paint.Align.LEFT); canvas.drawText (MatumbaMan's blog, 200,200, mTextPaint); mTextPaint.setTextAlign (Paint.Align.RIGHT); canvas.drawText (MatumbaMan's blog, 200,300, mTextPaint); mTextPaint.setTextAlign (Paint.Align.CENTER); canvas.drawText (MatumbaMan's blog, 200,400, mTextPaint)
2.4 setShadowLayer Shadow
SetShadowLayer (float radius, float dx, float dy, int shadowColor) sets shadows
Radius setting angle, dx,dy controls the font to appear up and down, there are positive and negative points, dx positive and negative represents the right and left, dy positive and negative represents the bottom.
MTextPaint.setTextAlign (Paint.Align.LEFT); mTextPaint.setShadowLayer (10,-20,40, Color.GRAY); canvas.drawText (MatumbaMan blog, 200,200, mTextPaint); mTextPaint.setTextAlign (Paint.Align.RIGHT); canvas.drawText (MatumbaMan blog, 200,300, mTextPaint); mTextPaint.setTextAlign (Paint.Align.CENTER); canvas.drawText (MatumbaMan blog, 200,400, mTextPaint)
2.5 setStrokeCap
SetStrokeCap (Paint.Cap.ROUND) sets the style for drawing start and end points
Three styles ROUND,BUTT,SQUARE,
Cap.ROUND (circle)
Cap.SQUARE (Square)
Paint.Cap.BUTT (none)
Path path = new Path (); path.moveTo (100,100); path.lineTo (100,200); path.lineTo (200,300); canvas.drawPath (path, mPaint2); / / No path.reset (); path.moveTo (300,100); path.lineTo (300,200); path.lineTo (400,300); mPaint2.setStrokeCap (Paint.Cap.ROUND); / / Circle canvas.drawPath (path, mPaint2); path.reset (); path.moveTo (500,100); path.lineTo (500,200) Path.lineTo (600,300); mPaint2.setStrokeCap (Paint.Cap.SQUARE); / / Party canvas.drawPath (path, mPaint2)
2.6 setStrokeJoin
SetStrokeJoin (Paint.Join join), which sets the style for drawing path connection points
Join.MITER (acute angle at the joint)
Join.Round (the joint is an arc)
Join.BEVEL (straight line at the joint)
Path path = new Path (); path.moveTo (100,100); path.lineTo (100200); path.lineTo (200,300); mPaint2.setStrokeJoin (Paint.Join.MITER); canvas.drawPath (path, mPaint2); path.reset (); path.moveTo (300,100); path.lineTo (300,200); path.lineTo (400,300); mPaint2.setStrokeJoin (Paint.Join.ROUND); canvas.drawPath (path, mPaint2); path.reset (); path.moveTo (500,100); path.lineTo (500,200) Path.lineTo (600,300); mPaint2.setStrokeJoin (Paint.Join.BEVEL); canvas.drawPath (path, mPaint2)
The above is all the contents of the article "how to use Paint, a native drawing tool for Androi". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 229
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.