android.graphics.Paint类详解

来源:互联网 发布:数据库系统全书第二版 编辑:程序博客网 时间:2024/04/29 03:25
public class

Paint

extends Object
java.lang.Object   ↳android.graphics.PaintKnown Direct Subclasses

Class Overview

The Paint class holds the style and color information about how to draw geometries, text and bitmaps.

enum    Paint.Align                      Align specifies how drawText aligns its text relative to the [x,y] coordinates. 
enum    Paint.CapThe                Cap specifies the treatment for the beginning and ending of stroked lines and paths. 
class    Paint.FontMetrics          Class that describes the various metrics for a font at a given text size. 
class    Paint.FontMetrics           IntConvenience method for callers that want to have FontMetrics values as integers. 
enum    Paint.Join                       The Join specifies the treatment where lines and curve segments join on a stroked path. 
enum    Paint.Style The Style specifies if the primitive being drawn is filled, stroked, or both (in the same color). 

Summary

Public ConstructorsPaint()创建默认设置的画笔
Create a new paint with default settings.
Paint(int flags)创建指定标记的画笔,类似于给画笔取了个名字
Create a new paint with the specified flags.
Paint(Paint paint)创建和现有画笔属性相同的画笔
Create a new paint, initialized with the attributes in the specified paint parameter.
Public Methodsfloatascent()
Return the distance above (negative) the baseline (ascent) based on the current typeface and text size.

1.基准点是baseline

2.ascent:是baseline之上至字符最高处的距离

3.descent:是baseline之下至字符最低处的距离

4.leading:是上一行字符的descent到下一行的ascent之间的距离,也就是相邻行间的空白距离

5.top:是指的是最高字符到baseline的值,即ascent的最大值

6.bottom:是指最低字符到baseline的值,即descent的最大值

intbreakText(CharSequence text, int start, int end, boolean measureForwards, float maxWidth, float[] measuredWidth)
Measure the text, stopping early if the measured width exceeds maxWidth.
intbreakText(String text, boolean measureForwards, float maxWidth, float[] measuredWidth)
Measure the text, stopping early if the measured width exceeds maxWidth.
intbreakText(char[] text, int index, int count, float maxWidth, float[] measuredWidth)
Measure the text, stopping early if the measured width exceeds maxWidth.
voidclearShadowLayer()
Clear the shadow layer.
floatdescent()
Return the distance below (positive) the baseline (descent) based on the current typeface and text size.
intgetAlpha()
Helper to getColor() that just returns the color's alpha value.
intgetColor()
Return the paint's color.
ColorFiltergetColorFilter()
Get the paint's colorfilter (maybe be null).
booleangetFillPath(Path src, Path dst)
Applies any/all effects (patheffect, stroking) to src, returning the result in dst.
intgetFlags()
Return the paint's flags.
floatgetFontMetrics(Paint.FontMetrics metrics)
Return the font's recommended interline spacing, given the Paint's settings for typeface, textSize, etc.
Paint.FontMetricsgetFontMetrics()
Allocates a new FontMetrics object, and then calls getFontMetrics(fm) with it, returning the object.
Paint.FontMetricsIntgetFontMetricsInt()intgetFontMetricsInt(Paint.FontMetricsInt fmi)
Return the font's interline spacing, given the Paint's settings for typeface, textSize, etc.
floatgetFontSpacing()
Return the recommend line spacing based on the current typeface and text size.
intgetHinting()
Return the paint's hinting mode.
MaskFiltergetMaskFilter()
Get the paint's maskfilter object.
PathEffectgetPathEffect()
Get the paint's patheffect object.
RasterizergetRasterizer()
Get the paint's rasterizer (or null).
ShadergetShader()
Get the paint's shader object.
Paint.CapgetStrokeCap()
Return the paint's Cap, controlling how the start and end of stroked lines and paths are treated.
Paint.JoingetStrokeJoin()
Return the paint's stroke join type.
floatgetStrokeMiter()
Return the paint's stroke miter value.
floatgetStrokeWidth()
Return the width for stroking.
Paint.StylegetStyle()
Return the paint's style, used for controlling how primitives' geometries are interpreted (except for drawBitmap, which always assumes 
FILL_STYLE).
Paint.AligngetTextAlign()
Return the paint's Align value for drawing text.
voidgetTextBounds(char[] text, int index, int count, Rect bounds)
Return in bounds (allocated by the caller) the smallest rectangle that encloses all of the characters, with an implied origin at (0,0).
voidgetTextBounds(String text, int start, int end, Rect bounds)
Return in bounds (allocated by the caller) the smallest rectangle that encloses all of the characters, with an implied origin at (0,0).
voidgetTextPath(String text, int start, int end, float x, float y, Path path)
Return the path (outline) for the specified text.
voidgetTextPath(char[] text, int index, int count, float x, float y, Path path)
Return the path (outline) for the specified text.
floatgetTextScaleX()
Return the paint's horizontal scale factor for text.
floatgetTextSize()
Return the paint's text size.
floatgetTextSkewX()
Return the paint's horizontal skew factor for text.
intgetTextWidths(String text, float[] widths)
Return the advance widths for the characters in the string.
intgetTextWidths(CharSequence text, int start, int end, float[] widths)
Return the advance widths for the characters in the string.
intgetTextWidths(String text, int start, int end, float[] widths)
Return the advance widths for the characters in the string.
intgetTextWidths(char[] text, int index, int count, float[] widths)
Return the advance widths for the characters in the string.
TypefacegetTypeface()
Get the paint's typeface object.
XfermodegetXfermode()
Get the paint's xfermode object.
final booleanisAntiAlias()
Helper for getFlags(), returning true if ANTI_ALIAS_FLAG bit is set AntiAliasing smooths out the edges of what is being drawn, but is has 
no impact on the interior of the shape.
final booleanisDither()
Helper for getFlags(), returning true if DITHER_FLAG bit is set Dithering affects how colors that are higher precision than the device are 
down-sampled.
final booleanisFakeBoldText()
Helper for getFlags(), returning true if FAKE_BOLD_TEXT_FLAG bit is set
final booleanisFilterBitmap()
Whether or not the bitmap filter is activated.
final booleanisLinearText()
Helper for getFlags(), returning true if LINEAR_TEXT_FLAG bit is set
final booleanisStrikeThruText()
Helper for getFlags(), returning true if STRIKE_THRU_TEXT_FLAG bit is set
final booleanisSubpixelText()
Helper for getFlags(), returning true if SUBPIXEL_TEXT_FLAG bit is set
final booleanisUnderlineText()
Helper for getFlags(), returning true if UNDERLINE_TEXT_FLAG bit is set
floatmeasureText(String text)测量字符串的宽度
Return the width of the text.
floatmeasureText(CharSequence text, int start, int end)
Return the width of the text.
floatmeasureText(String text, int start, int end)
Return the width of the text.
floatmeasureText(char[] text, int index, int count)
Return the width of the text.
voidreset()重置画笔,回到画笔默认设置
Restores the paint to its default settings.
voidset(Paint src)相当于实例化Paint(Paint paint);时设置画笔
Copy the fields from src into this paint.
voidsetARGB(int a, int r, int g, int b)设置绘制的颜色,a代表透明度,r,g,b代表颜色值
Helper to setColor(), that takes a,r,g,b and constructs the color int
voidsetAlpha(int a)设置透明度值 
Helper to setColor(), that only assigns the color's alpha value, leaving its r,g,b values unchanged.
voidsetAntiAlias(boolean aa)设置是否使用抗锯齿功能,会消耗较大资源,绘制图形速度会变慢。,true为无锯齿
Helper for setFlags(), setting or clearing the ANTI_ALIAS_FLAG bit AntiAliasing smooths out the edges of what is being drawn, 
but is has no impact on the interior of the shape.
voidsetColor(int color)设置绘制的颜色,使用颜色值来表示,该颜色值包括透明度和RGB颜色
Set the paint's color.
ColorFiltersetColorFilter(ColorFilter filter)设置颜色过滤器,可以在绘制颜色时实现不用颜色的变换效果
Set or clear the paint's colorfilter, returning the parameter.
voidsetDither(boolean dither)设定是否使用图像抖动处理,会使绘制出来的图片颜色更加平滑和饱满,图像更加清晰
Helper for setFlags(), setting or clearing the DITHER_FLAG bit Dithering affects how colors that are higher precision than the 
device are down-sampled.
voidsetFakeBoldText(boolean fakeBoldText)模拟实现粗体文字,设置在小字体上效果会非常差 
Helper for setFlags(), setting or clearing the FAKE_BOLD_TEXT_FLAG bit
voidsetFilterBitmap(boolean filter)如果该项设置为true,则图像在动画进行中会滤掉对Bitmap图像的优化操作,加快显示  
速度,本设置项依赖于dither和xfermode的设置  
Helper for setFlags(), setting or clearing the FILTER_BITMAP_FLAG bit.
voidsetFlags(int flags)相当于Paint(int flags);时的设置
Set the paint's flags.
voidsetHinting(int mode)
Set the paint's hinting mode.
voidsetLinearText(boolean linearText)
Helper for setFlags(), setting or clearing the LINEAR_TEXT_FLAG bit
MaskFiltersetMaskFilter(MaskFilter maskfilter)设置MaskFilter,可以用不同的MaskFilter实现滤镜的效果,如滤化,立体等
Set or clear the maskfilter object.
PathEffectsetPathEffect(PathEffect effect)设置绘制路径的效果,如点画线等
Set or clear the patheffect object.
RasterizersetRasterizer(Rasterizer rasterizer)
Set or clear the rasterizer object.
ShadersetShader(Shader shader)设置图像效果,使用Shader可以绘制出各种渐变效果
Set or clear the shader object.
voidsetShadowLayer(float radius, float dx, float dy, int color)在图形下面设置阴影层,产生阴影效果,radius为阴影的角度,
dx和dy为阴影在x轴和y轴上的距离,color为阴影的颜色
This draws a shadow layer below the main layer, with the specified offset and color, and blur radius.
voidsetStrikeThruText(boolean strikeThruText)设置带有删除线的效果  
Helper for setFlags(), setting or clearing the STRIKE_THRU_TEXT_FLAG bit
voidsetStrokeCap(Paint.Cap cap)当画笔样式为STROKE或FILL_OR_STROKE时,设置笔刷的图形样式,如圆形样式 
Cap.ROUND,或方形样式Cap.SQUARE 
Set the paint's Cap.
voidsetStrokeJoin(Paint.Join join)设置绘制时各图形的结合方式,如平滑效果等  
Set the paint's Join.
voidsetStrokeMiter(float miter)
Set the paint's stroke miter value.
voidsetStrokeWidth(float width)当画笔样式为STROKE或FILL_OR_STROKE时,设置笔刷的粗细度
Set the width for stroking.
voidsetStyle(Paint.Style style)设置画笔的样式,为FILL,FILL_OR_STROKE,或STROKE 空心或者实心
Set the paint's style, used for controlling how primitives' geometries are interpreted 
(except for drawBitmap, which always assumes Fill).
voidsetSubpixelText(boolean subpixelText)设置该项为true,将有助于文本在LCD屏幕上的显示效果  
Helper for setFlags(), setting or clearing the SUBPIXEL_TEXT_FLAG bit
voidsetTextAlign(Paint.Align align)设置绘制文字的对齐方向 
Set the paint's text alignment.
voidsetTextScaleX(float scaleX) 设置绘制文字x轴的缩放比例,可以实现文字的拉伸的效果
Set the paint's horizontal scale factor for text.
voidsetTextSize(float textSize)设置绘制文字的字号大小
Set the paint's text size.
voidsetTextSkewX(float skewX)设置斜体文字,skewX为倾斜弧度 
Set the paint's horizontal skew factor for text.
TypefacesetTypeface(Typeface typeface)设置Typeface对象,即字体风格,包括粗体,斜体以及衬线体,非衬线体等
Set or clear the typeface object.
voidsetUnderlineText(boolean underlineText) 设置带有下划线的文字效果
Helper for setFlags(), setting or clearing the UNDERLINE_TEXT_FLAG bit
XfermodesetXfermode(Xfermode xfermode)设置图形重叠时的处理方式,如合并,取交集或并集,经常用来制作橡皮的擦除效果  
Set or clear the xfermode object.
Protected Methodsvoidfinalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.








1 0
原创粉丝点击