android.graphics.Paint类详解

public class

Paint

extends  Object
java.lang.Object
   ↳ android.graphics.Paint
Known 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 Constructors
Paint() 创建默认设置的画笔
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 Methods
float ascent()
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的最大值

int breakText( CharSequence text, int start, int end, boolean measureForwards, float maxWidth, float[] measuredWidth)
Measure the text, stopping early if the measured width exceeds maxWidth.
int breakText( String text, boolean measureForwards, float maxWidth, float[] measuredWidth)
Measure the text, stopping early if the measured width exceeds maxWidth.
int breakText(char[] text, int index, int count, float maxWidth, float[] measuredWidth)
Measure the text, stopping early if the measured width exceeds maxWidth.
void clearShadowLayer()
Clear the shadow layer.
float descent()
Return the distance below (positive) the baseline (descent) based on the current typeface and text size.
int getAlpha()
Helper to getColor() that just returns the color's alpha value.
int getColor()
Return the paint's color.
ColorFilter getColorFilter()
Get the paint's colorfilter (maybe be null).
boolean getFillPath( Path src,  Path dst)
Applies any/all effects (patheffect, stroking) to src, returning the result in dst.
int getFlags()
Return the paint's flags.
float getFontMetrics( Paint.FontMetrics metrics)
Return the font's recommended interline spacing, given the Paint's settings for typeface, textSize, etc.
Paint.FontMetrics getFontMetrics()
Allocates a new FontMetrics object, and then calls getFontMetrics(fm) with it, returning the object.
Paint.FontMetricsInt getFontMetricsInt()
int getFontMetricsInt( Paint.FontMetricsInt fmi)
Return the font's interline spacing, given the Paint's settings for typeface, textSize, etc.
float getFontSpacing()
Return the recommend line spacing based on the current typeface and text size.
int getHinting()
Return the paint's hinting mode.
MaskFilter getMaskFilter()
Get the paint's maskfilter object.
PathEffect getPathEffect()
Get the paint's patheffect object.
Rasterizer getRasterizer()
Get the paint's rasterizer (or null).
Shader getShader()
Get the paint's shader object.
Paint.Cap getStrokeCap()
Return the paint's Cap, controlling how the start and end of stroked lines and paths are treated.
Paint.Join getStrokeJoin()
Return the paint's stroke join type.
float getStrokeMiter()
Return the paint's stroke miter value.
float getStrokeWidth()
Return the width for stroking.
Paint.Style getStyle()
Return the paint's style, used for controlling how primitives' geometries are interpreted (except for drawBitmap, which always assumes 
FILL_STYLE).
Paint.Align getTextAlign()
Return the paint's Align value for drawing text.
void getTextBounds(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).
void getTextBounds( 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).
void getTextPath( String text, int start, int end, float x, float y,  Path path)
Return the path (outline) for the specified text.
void getTextPath(char[] text, int index, int count, float x, float y,  Path path)
Return the path (outline) for the specified text.
float getTextScaleX()
Return the paint's horizontal scale factor for text.
float getTextSize()
Return the paint's text size.
float getTextSkewX()
Return the paint's horizontal skew factor for text.
int getTextWidths( String text, float[] widths)
Return the advance widths for the characters in the string.
int getTextWidths( CharSequence text, int start, int end, float[] widths)
Return the advance widths for the characters in the string.
int getTextWidths( String text, int start, int end, float[] widths)
Return the advance widths for the characters in the string.
int getTextWidths(char[] text, int index, int count, float[] widths)
Return the advance widths for the characters in the string.
Typeface getTypeface()
Get the paint's typeface object.
Xfermode getXfermode()
Get the paint's xfermode object.
final boolean isAntiAlias()
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 boolean isDither()
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 boolean isFakeBoldText()
Helper for getFlags(), returning true if FAKE_BOLD_TEXT_FLAG bit is set
final boolean isFilterBitmap()
Whether or not the bitmap filter is activated.
final boolean isLinearText()
Helper for getFlags(), returning true if LINEAR_TEXT_FLAG bit is set
final boolean isStrikeThruText()
Helper for getFlags(), returning true if STRIKE_THRU_TEXT_FLAG bit is set
final boolean isSubpixelText()
Helper for getFlags(), returning true if SUBPIXEL_TEXT_FLAG bit is set
final boolean isUnderlineText()
Helper for getFlags(), returning true if UNDERLINE_TEXT_FLAG bit is set
float measureText( String text) 测量字符串的宽度
Return the width of the text.
float measureText( CharSequence text, int start, int end)
Return the width of the text.
float measureText( String text, int start, int end)
Return the width of the text.
float measureText(char[] text, int index, int count)
Return the width of the text.
void reset() 重置画笔,回到画笔默认设置
Restores the paint to its default settings.
void set( Paint src) 相当于实例化Paint(Paint paint);时设置画笔
Copy the fields from src into this paint.
void setARGB(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
void setAlpha(int a) 设置透明度值 
Helper to setColor(), that only assigns the color's alpha value, leaving its r,g,b values unchanged.
void setAntiAlias(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.
void setColor(int color) 设置绘制的颜色,使用颜色值来表示,该颜色值包括透明度和RGB颜色
Set the paint's color.
ColorFilter setColorFilter( ColorFilter filter) 设置颜色过滤器,可以在绘制颜色时实现不用颜色的变换效果
Set or clear the paint's colorfilter, returning the parameter.
void setDither(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.
void setFakeBoldText(boolean fakeBoldText) 模拟实现粗体文字,设置在小字体上效果会非常差 
Helper for setFlags(), setting or clearing the FAKE_BOLD_TEXT_FLAG bit
void setFilterBitmap(boolean filter) 如果该项设置为true,则图像在动画进行中会滤掉对Bitmap图像的优化操作,加快显示  
速度,本设置项依赖于dither和xfermode的设置  
Helper for setFlags(), setting or clearing the FILTER_BITMAP_FLAG bit.
void setFlags(int flags) 相当于Paint(int flags);时的设置
Set the paint's flags.
void setHinting(int mode)
Set the paint's hinting mode.
void setLinearText(boolean linearText)
Helper for setFlags(), setting or clearing the LINEAR_TEXT_FLAG bit
MaskFilter setMaskFilter( MaskFilter maskfilter) 设置MaskFilter,可以用不同的MaskFilter实现滤镜的效果,如滤化,立体等
Set or clear the maskfilter object.
PathEffect setPathEffect( PathEffect effect) 设置绘制路径的效果,如点画线等
Set or clear the patheffect object.
Rasterizer setRasterizer( Rasterizer rasterizer)
Set or clear the rasterizer object.
Shader setShader( Shader shader) 设置图像效果,使用Shader可以绘制出各种渐变效果
Set or clear the shader object.
void setShadowLayer(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.
void setStrikeThruText(boolean strikeThruText) 设置带有删除线的效果   
Helper for setFlags(), setting or clearing the STRIKE_THRU_TEXT_FLAG bit
void setStrokeCap( Paint.Cap cap) 当画笔样式为STROKE或FILL_OR_STROKE时,设置笔刷的图形样式,如圆形样式 
Cap.ROUND,或方形样式Cap.SQUARE 
Set the paint's Cap.
void setStrokeJoin( Paint.Join join) 设置绘制时各图形的结合方式,如平滑效果等   
Set the paint's Join.
void setStrokeMiter(float miter)
Set the paint's stroke miter value.
void setStrokeWidth(float width) 当画笔样式为STROKE或FILL_OR_STROKE时,设置笔刷的粗细度
Set the width for stroking.
void setStyle( 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).
void setSubpixelText(boolean subpixelText) 设置该项为true,将有助于文本在LCD屏幕上的显示效果  
Helper for setFlags(), setting or clearing the SUBPIXEL_TEXT_FLAG bit
void setTextAlign( Paint.Align align) 设置绘制文字的对齐方向 
Set the paint's text alignment.
void setTextScaleX(float scaleX)   设置绘制文字x轴的缩放比例,可以实现文字的拉伸的效果
Set the paint's horizontal scale factor for text.
void setTextSize(float textSize) 设置绘制文字的字号大小
Set the paint's text size.
void setTextSkewX(float skewX) 设置斜体文字,skewX为倾斜弧度 
Set the paint's horizontal skew factor for text.
Typeface setTypeface( Typeface typeface) 设置Typeface对象,即字体风格,包括粗体,斜体以及衬线体,非衬线体等
Set or clear the typeface object.
void setUnderlineText(boolean underlineText)   设置带有下划线的文字效果
Helper for setFlags(), setting or clearing the UNDERLINE_TEXT_FLAG bit
Xfermode setXfermode( Xfermode xfermode) 设置图形重叠时的处理方式,如合并,取交集或并集,经常用来制作橡皮的擦除效果   
Set or clear the xfermode object.
Protected Methods
void finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.








  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值