android.graphics.Paint类详解

转载 2016年08月29日 14:29:04

android.graphics.Paint类详解

标签: AndroidPaint
 1762人阅读 评论(0) 收藏 举报
 分类:

目录(?)[+]

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.

相关文章推荐

Android Graphics (一) :Paint

Paint还有很多方法供我们使用,这里就不一一演示了。下面我们简单的介绍一下。Paint类介绍Paint即画笔,在绘图过程中起到了极其重要的作用,画笔主要保存了颜色,样式等绘制信息,指定了如何绘制文本...
  • Todo_
  • Todo_
  • 2016年02月18日 10:39
  • 262

android图形系统之Paint(画笔)类详解

* Paint类介绍        *         * Paint即画笔,在绘图过程中起到了极其重要的作用,画笔主要保存了颜色,        * 样式等绘制信息,指定了如何绘制...

Android中Paint画笔类的使用详解

Paint类的使用介绍 Android自定义View中想在画笔canvas上边画图要学会使用画笔类Paint。我们需要将画笔的相关属性设置好,才能画出想要的图片,例如设置画笔的颜色、画笔字体的相关...

android.graphics.Canvas类详解

public class Canvas extends Object java.lang.Object    ↳ android.graphics.Canvas Clas...

android.graphics.Rect类的详解

public final class Rect extends Object implements Parcelable java.lang.Object    ↳ android....

Android 自定义控件-Canvas和Paint绘图详解-手把手带你绘制一个时钟.

1,Android - Paint基础在自定义控件时,经常需要使用canvas、paint等,在canvas类中,绘画基本都是靠drawXXX()方法来完成的,在这些方法中,很多时候都需要用到pain...

Android View — Paint 详解

Android View — Paint 详解在Android View 的概念中,Paint 如名字所代表的含义,是画笔的意思。像我们平时画图一样,Paint就是相当于笔,而Canvas就是纸,这里...

Android基础入门教程——8.3.4 Paint API之—— Xfermode与PorterDuff详解(一)

不知道标题这两个玩意你熟不熟悉啦,如果自己实现过圆角或者圆形图片,相信对这两个名词 并不模式,一时半伙没想起来?没关系,下面这个图你可曾见过? PS:网上都说在:\samples\androi...

Android Paint的使用详解

尊重原创,转载请标明出处    http://blog.csdn.net/abcdef314159 自定义控件具有很强的灵活性,可以根据你的想法画出各种各样的图案,在Android中如果是自定义控件的...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:android.graphics.Paint类详解
举报原因:
原因补充:

(最多只允许输入30个字)