public class Canvas
extends Object
| java.lang.Object | |
| android.graphics.Canvas | |
Canvas类包含“draw”调用。 要绘制一些东西,你需要4个基本组件:一个位图来保存像素,一个Canvas来承载绘图调用(写入位图),一个绘图基元(例如Rect,Path,文本,位图)和一个绘图描述绘图的颜色和样式)。
有关如何使用Canvas的更多信息,请阅读 Canvas and Drawables开发人员指南。
Nested classes |
|
|---|---|
枚举 |
Canvas.EdgeType
|
枚举 |
Canvas.VertexMode
|
常量(Constants) |
|
|---|---|
int |
ALL_SAVE_FLAG restore()被调用时恢复所有内容(标准保存标志)。 |
int |
CLIP_SAVE_FLAG 调用restore()时恢复当前剪辑。 |
int |
CLIP_TO_LAYER_SAVE_FLAG 将剪贴画拖到屏外图层的边界,省略掉自己的危险。 |
int |
FULL_COLOR_LAYER_SAVE_FLAG 该图层需要每个颜色通道具有完整的8位精度。 |
int |
HAS_ALPHA_LAYER_SAVE_FLAG 该图层需要每个像素的Alpha通道。 |
int |
MATRIX_SAVE_FLAG restore()被调用时恢复当前矩阵。 |
Public constructors |
|
|---|---|
Canvas() 构建一个空的栅格画布。 |
|
Canvas(Bitmap bitmap) 构造一个具有指定位图的画布进行绘制。 |
|
公共方法(Public methods) |
|
|---|---|
boolean |
clipPath(Path path, Region.Op op) 使用指定的路径修改当前剪辑。 |
boolean |
clipPath(Path path) 将当前剪辑与指定路径相交。 |
boolean |
clipRect(float left, float top, float right, float bottom, Region.Op op) 使用指定的矩形修改当前剪辑,该矩形以局部坐标表示。 |
boolean |
clipRect(RectF rect) 将当前剪辑与指定的矩形相交,该矩形以局部坐标表示。 |
boolean |
clipRect(Rect rect, Region.Op op) 使用指定的矩形修改当前剪辑,该矩形以局部坐标表示。 |
boolean |
clipRect(int left, int top, int right, int bottom) 将当前剪辑与指定的矩形相交,该矩形以局部坐标表示。 |
boolean |
clipRect(float left, float top, float right, float bottom) 将当前剪辑与指定的矩形相交,该矩形以局部坐标表示。 |
boolean |
clipRect(RectF rect, Region.Op op) 使用指定的矩形修改当前剪辑。 |
boolean |
clipRect(Rect rect) 将当前剪辑与指定的矩形相交,该矩形以局部坐标表示。 |
boolean |
clipRegion(Region region) 此方法在API级别21中已弃用。与所有其他剪辑调用不同,此API不尊重当前矩阵。 使用 |
boolean |
clipRegion(Region region, Region.Op op) 此方法在API级别21中已弃用。与所有其他剪辑调用不同,此API不尊重当前矩阵。 使用 |
void |
concat(Matrix matrix) 用指定的矩阵预处理当前矩阵。 |
void |
drawARGB(int a, int r, int g, int b) 使用srcover porterduff模式,用指定的ARGB颜色填充整个画布的位图(仅限于当前剪辑)。 |
void |
drawArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle, boolean useCenter, Paint paint) 绘制指定的弧,该弧将被缩放以适合指定的椭圆内。 |
void |
drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint paint) 绘制指定的弧,该弧将被缩放以适合指定的椭圆内。 |
void |
drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) 使用指定的矩阵绘制位图。 |
void |
drawBitmap(int[] colors, int offset, int stride, float x, float y, int width, int height, boolean hasAlpha, Paint paint) 此方法在API级别21中已被弃用。每次调用此方法时, |
void |
drawBitmap(int[] colors, int offset, int stride, int x, int y, int width, int height, boolean hasAlpha, Paint paint) 此方法在API级别21中已被弃用。每次调用此方法时,使用 |
void |
drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) 绘制指定的位图,自动缩放/翻译以填充目标矩形。 |
void |
drawBitmap(Bitmap bitmap, float left, float top, Paint paint) 使用由当前矩阵转换的指定颜料绘制指定的位图,其顶部/左侧角在(x,y)处。 |
void |
drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) 绘制指定的位图,自动缩放/翻译以填充目标矩形。 |
void |
drawBitmapMesh(Bitmap bitmap, int meshWidth, int meshHeight, float[] verts, int vertOffset, int[] colors, int colorOffset, Paint paint) 通过网格绘制位图,其中网格顶点均匀分布在位图中。 |
void |
drawCircle(float cx, float cy, float radius, Paint paint) 使用指定的绘图绘制指定的圆。 |
void |
drawColor(int color) 使用srcover porterduff模式,用指定的颜色填充整个画布的位图(限制为当前剪辑)。 |
void |
drawColor(int color, PorterDuff.Mode mode) 用指定的颜色和porter-duff xfermode填充整个画布的位图(仅限于当前剪辑)。 |
void |
drawLine(float startX, float startY, float stopX, float stopY, Paint paint) 使用指定的绘图绘制一条具有指定的起点和停止x,y坐标的线段。 |
void |
drawLines(float[] pts, int offset, int count, Paint paint) 画一系列线条。 |
void |
drawLines(float[] pts, Paint paint) |
void |
drawOval(float left, float top, float right, float bottom, Paint paint) 使用指定的绘图绘制指定的椭圆。 |
void |
drawOval(RectF oval, Paint paint) 使用指定的绘图绘制指定的椭圆。 |
void |
drawPaint(Paint paint) 使用指定的油漆填充整个画布的位图(仅限于当前剪辑)。 |
void |
drawPath(Path path, Paint paint) 使用指定的绘图绘制指定的路径。 |
void |
drawPicture(Picture picture, Rect dst) 绘制图片,拉伸以适合dst矩形。 |
void |
drawPicture(Picture picture, RectF dst) 绘制图片,拉伸以适合dst矩形。 |
void |
drawPicture(Picture picture) 保存画布状态,绘制图片并恢复画布状态。 |
void |
drawPoint(float x, float y, Paint paint) 用于绘制单个点的drawPoints()的帮助器。 |
void |
drawPoints(float[] pts, int offset, int count, Paint paint) 画出一系列点。 |
void |
drawPoints(float[] pts, Paint paint) 用于drawPoints()的助手,假定您要绘制整个数组 |
void |
drawPosText(String text, float[] pos, Paint paint) 此方法在API级别16中已弃用。此方法不支持字形组合和分解,因此不应用于渲染复杂脚本。 它也不处理补充字符(例如表情符号)。 |
void |
drawPosText(char[] text, int index, int count, float[] pos, Paint paint) 此方法在API级别16中已弃用。此方法不支持字形组合和分解,因此不应用于渲染复杂脚本。 它也不处理补充字符(例如表情符号)。 |
void |
drawRGB(int r, int g, int b) 使用srcover porterduff模式,用指定的RGB颜色填充整个画布的位图(仅限于当前剪辑)。 |
void |
drawRect(float left, float top, float right, float bottom, Paint paint) 使用指定的绘图绘制指定的Rect。 |
void |
drawRect(Rect r, Paint paint) 使用指定的Paint绘制指定的Rect。 |
void |
drawRect(RectF rect, Paint paint) 使用指定的绘图绘制指定的Rect。 |
void |
drawRoundRect(RectF rect, float rx, float ry, Paint paint) 使用指定的绘图绘制指定的圆角。 |
void |
drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, Paint paint) 使用指定的绘图绘制指定的圆角。 |
void |
drawText(CharSequence text, int start, int end, float x, float y, Paint paint) 绘制指定范围的文本,由start / end指定,其原点位于(x,y)指定的Paint中。 |
void |
drawText(String text, float x, float y, Paint paint) 使用指定的绘图在原点(x,y)处绘制文本。 |
void |
drawText(String text, int start, int end, float x, float y, Paint paint) 使用指定的绘图在原点(x,y)处绘制文本。 |
void |
drawText(char[] text, int index, int count, float x, float y, Paint paint) 使用指定的绘图在原点(x,y)处绘制文本。 |
void |
drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint) 沿着指定的路径使用指定的绘图绘制文本,原点位于(x,y)处。 |
void |
drawTextOnPath(char[] text, int index, int count, Path path, float hOffset, float vOffset, Paint paint) 沿着指定的路径使用指定的绘图绘制文本,原点位于(x,y)处。 |
void |
drawTextRun(char[] text, int index, int count, int contextIndex, int contextCount, float x, float y, boolean isRtl, Paint paint) 在单一方向上绘制一段文本,并带有用于复杂文本整形的可选上下文。 |
void |
drawTextRun(CharSequence text, int start, int end, int contextStart, int contextEnd, float x, float y, boolean isRtl, Paint paint) 在单一方向上绘制一段文本,并带有用于复杂文本整形的可选上下文。 |
void |
drawVertices(Canvas.VertexMode mode, int vertexCount, float[] verts, int vertOffset, float[] texs, int texOffset, int[] colors, int colorOffset, short[] indices, int indexOffset, int indexCount, Paint paint) 绘制顶点数组,解释为三角形(基于模式)。 |
boolean |
getClipBounds(Rect bounds) 返回bounds参数中当前剪辑的边界(以本地坐标表示),如果非空,则返回true。 |
final Rect |
getClipBounds() 检索当前剪辑的边界(以本地坐标)。 |
int |
getDensity() 返回画布的目标密度。 |
DrawFilter |
getDrawFilter() |
int |
getHeight() 返回当前绘图图层的高度 |
final Matrix |
getMatrix() 此方法在API级别16中已弃用 |
void |
getMatrix(Matrix ctm) 这种方法是在API级弃用16. |
int |
getMaximumBitmapHeight() 返回使用此画布绘制的位图的最大允许高度。 |
int |
getMaximumBitmapWidth() 返回使用此画布绘制的位图的最大允许宽度。 |
int |
getSaveCount() 返回Canvas专用堆栈上矩阵/剪辑状态的数量。 |
int |
getWidth() 返回当前绘图图层的宽度 |
boolean |
isHardwareAccelerated() 指示此Canvas是否使用硬件加速。 |
boolean |
isOpaque() 如果当前图层绘制的设备不透明,则返回true(即 |
boolean |
quickReject(float left, float top, float right, float bottom, Canvas.EdgeType type) 如果指定矩形在被当前矩阵转换后完全位于当前剪辑之外,则返回true。 |
boolean |
quickReject(Path path, Canvas.EdgeType type) 如果指定的路径在被当前矩阵转换后完全位于当前剪辑之外,则返回true。 |
boolean |
quickReject(RectF rect, Canvas.EdgeType type) 如果指定矩形在被当前矩阵转换后完全位于当前剪辑之外,则返回true。 |
void |
restore() 此调用将先前调用save(),并用于从上次保存调用后删除对矩阵/剪辑状态的所有修改。 |
void |
restoreToCount(int saveCount) 有效的方式来弹出任何调用save()之后发生的保存计数达到saveCount。 |
final void |
rotate(float degrees, float px, float py) 用指定的旋转预先缩放当前矩阵。 |
void |
rotate(float degrees) 用指定的旋转预先缩放当前矩阵。 |
int |
save(int saveFlags) 基于saveFlags,可以将当前矩阵和剪辑保存到私有堆栈中。 |
int |
save() 保存当前矩阵并剪辑到私有堆栈上。 |
int |
saveLayer(float left, float top, float right, float bottom, Paint paint) 方便saveLayer(左,上,右,下,绘制, |
int |
saveLayer(RectF bounds, Paint paint, int saveFlags) 它的行为与save()相同,但是它还分配并将图形重定向到离屏位图。 |
int |
saveLayer(RectF bounds, Paint paint) 方便saveLayer(边界,油漆, |
int |
saveLayer(float left, float top, float right, float bottom, Paint paint, int saveFlags) saveLayer()的帮助版本取4个值而不是RectF。 |
int |
saveLayerAlpha(float left, float top, float right, float bottom, int alpha, int saveFlags) saveLayerAlpha()的帮助器,取4个值而不是RectF。 |
int |
saveLayerAlpha(RectF bounds, int alpha, int saveFlags) 它的行为与save()相同,但是它还分配并将图形重定向到离屏位图。 |
int |
saveLayerAlpha(float left, float top, float right, float bottom, int alpha) saveLayerAlpha的帮助器(左,顶部,右侧,底部,alpha, |
int |
saveLayerAlpha(RectF bounds, int alpha) saveLayerAlpha方便(边界,alpha, |
final void |
scale(float sx, float sy, float px, float py) 用指定的比例预先缩放当前矩阵。 |
void |
scale(float sx, float sy) 用指定的比例预先缩放当前矩阵。 |
void |
setBitmap(Bitmap bitmap) 指定要绘制的画布的位图。 |
void |
setDensity(int density) 指定此Canvas的支持位图的密度。 |
void |
setDrawFilter(DrawFilter filter) |
void |
setMatrix(Matrix matrix) 用指定的矩阵完全替换当前矩阵。 |
void |
skew(float sx, float sy) 用指定的偏斜对当前矩阵进行预先扫描。 |
void |
translate(float dx, float dy) 用指定的转换对当前矩阵进行预处理 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
int ALL_SAVE_FLAG
restore()被调用时恢复所有内容(标准保存标志)。
注意:出于性能原因,强烈建议将此全部标志传递给 saveLayer()和 saveLayerAlpha()变体的任何调用。
常量值:31(0x0000001f)
int CLIP_TO_LAYER_SAVE_FLAG
将剪贴画拖到屏外图层的边界,省略掉自己的危险。
注意:强烈建议不要忽略此标志,以便调用saveLayer()和saveLayerAlpha()变体。 不通过这个标志通常会导致硬件加速渲染的性能极差。
常量值:16(0x00000010)
int FULL_COLOR_LAYER_SAVE_FLAG
该图层需要每个颜色通道具有完整的8位精度。
常量值:8(0x00000008)
int HAS_ALPHA_LAYER_SAVE_FLAG
该图层需要每个像素的Alpha通道。
常量值:4(0x00000004)
Canvas ()
构建一个空的栅格画布。 使用setBitmap()指定要绘制的位图。 初始目标密度是DENSITY_NONE ; 这通常会在为画布设置目标位图时进行替换。
Canvas (Bitmap bitmap)
构造一个具有指定位图的画布进行绘制。 位图必须是可变的。
画布的初始目标密度与给定的位图密度相同。
| 参数(Parameters) | |
|---|---|
bitmap |
Bitmap: Specifies a mutable bitmap for the canvas to draw into. |
boolean clipPath (Path path, Region.Op op)
使用指定的路径修改当前剪辑。
| 参数(Parameters) | |
|---|---|
path |
Path: The path to operate on the current clip |
op |
Region.Op: How the clip is modified |
| 返回(Returns) | |
|---|---|
boolean |
true if the resulting is non-empty |
boolean clipPath (Path path)
将当前剪辑与指定路径相交。
| 参数(Parameters) | |
|---|---|
path |
Path: The path to intersect with the current clip |
| 返回(Returns) | |
|---|---|
boolean |
true if the resulting is non-empty |
boolean clipRect (float left,
float top,
float right,
float bottom,
Region.Op op)
使用指定的矩形修改当前剪辑,该矩形以局部坐标表示。
| 参数(Parameters) | |
|---|---|
left |
float: The left side of the rectangle to intersect with the current clip |
top |
float: The top of the rectangle to intersect with the current clip |
right |
float: The right side of the rectangle to intersect with the current clip |
bottom |
float: The bottom of the rectangle to intersect with the current clip |
op |
Region.Op: How the clip is modified |
| 返回(Returns) | |
|---|---|
boolean |
true if the resulting clip is non-empty |
boolean clipRect (RectF rect)
将当前剪辑与指定的矩形相交,该矩形以局部坐标表示。
| 参数(Parameters) | |
|---|---|
rect |
RectF: The rectangle to intersect with the current clip. |
| 返回(Returns) | |
|---|---|
boolean |
true if the resulting clip is non-empty |
boolean clipRect (Rect rect, Region.Op op)
使用指定的矩形修改当前剪辑,该矩形以局部坐标表示。
| 参数(Parameters) | |
|---|---|
rect |
Rect: The rectangle to intersect with the current clip. |
op |
Region.Op: How the clip is modified |
| 返回(Returns) | |
|---|---|
boolean |
true if the resulting clip is non-empty |
boolean clipRect (int left,
int top,
int right,
int bottom)
将当前剪辑与指定的矩形相交,该矩形以局部坐标表示。
| 参数(Parameters) | |
|---|---|
left |
int: The left side of the rectangle to intersect with the current clip |
top |
int: The top of the rectangle to intersect with the current clip |
right |
int: The right side of the rectangle to intersect with the current clip |
bottom |
int: The bottom of the rectangle to intersect with the current clip |
| 返回(Returns) | |
|---|---|
boolean |
true if the resulting clip is non-empty |
boolean clipRect (float left,
float top,
float right,
float bottom)
将当前剪辑与指定的矩形相交,该矩形以局部坐标表示。
| 参数(Parameters) | |
|---|---|
left |
float: The left side of the rectangle to intersect with the current clip |
top |
float: The top of the rectangle to intersect with the current clip |
right |
float: The right side of the rectangle to intersect with the current clip |
bottom |
float: The bottom of the rectangle to intersect with the current clip |
| 返回(Returns) | |
|---|---|
boolean |
true if the resulting clip is non-empty |
boolean clipRect (RectF rect, Region.Op op)
使用指定的矩形修改当前剪辑。
| 参数(Parameters) | |
|---|---|
rect |
RectF: The rect to intersect with the current clip |
op |
Region.Op: How the clip is modified |
| 返回(Returns) | |
|---|---|
boolean |
true if the resulting clip is non-empty |
boolean clipRect (Rect rect)
将当前剪辑与指定的矩形相交,该矩形以局部坐标表示。
| 参数(Parameters) | |
|---|---|
rect |
Rect: The rectangle to intersect with the current clip. |
| 返回(Returns) | |
|---|---|
boolean |
true if the resulting clip is non-empty |
boolean clipRegion (Region region)
此方法在API级别21中已弃用。
与所有其他剪辑调用不同,此API不尊重当前矩阵。 使用clipRect(Rect)作为替代。
将当前剪辑与指定区域相交。 请注意,与使用当前矩阵转换其参数的clipRect()和clipPath()不同,clipRegion()假定其参数已位于当前图层位图的坐标系中,因此不执行转换。
| 参数(Parameters) | |
|---|---|
region |
Region: The region to operate on the current clip, based on op |
| 返回(Returns) | |
|---|---|
boolean |
true if the resulting is non-empty |
boolean clipRegion (Region region, Region.Op op)
此方法在API级别21中已弃用。
与所有其他剪辑调用不同,此API不尊重当前矩阵。 使用clipRect(Rect)作为替代。
修改指定区域的当前剪辑。 请注意,与使用当前矩阵转换其参数的clipRect()和clipPath()不同,clipRegion()假定其参数已位于当前图层位图的坐标系中,因此不执行转换。
| 参数(Parameters) | |
|---|---|
region |
Region: The region to operate on the current clip, based on op |
op |
Region.Op: How the clip is modified |
| 返回(Returns) | |
|---|---|
boolean |
true if the resulting is non-empty |
void concat (Matrix matrix)
用指定的矩阵预处理当前矩阵。 如果指定的矩阵为null,则此方法不执行任何操作。
| 参数(Parameters) | |
|---|---|
matrix |
Matrix: The matrix to preconcatenate with the current matrix |
void drawARGB (int a,
int r,
int g,
int b)
使用srcover porterduff模式,用指定的ARGB颜色填充整个画布的位图(仅限于当前剪辑)。
| 参数(Parameters) | |
|---|---|
a |
int: alpha component (0..255) of the color to draw onto the canvas |
r |
int: red component (0..255) of the color to draw onto the canvas |
g |
int: green component (0..255) of the color to draw onto the canvas |
b |
int: blue component (0..255) of the color to draw onto the canvas |
void drawArc (float left,
float top,
float right,
float bottom,
float startAngle,
float sweepAngle,
boolean useCenter,
Paint paint)
绘制指定的弧,该弧将被缩放以适合指定的椭圆内。
如果起始角度为负值或> = 360,则将起始角度视为模数360的起始角度。
如果扫掠角> = 360,则完全绘制椭圆。 请注意,这与SkPath :: arcTo略有不同,SkPath :: arcTo将模拟360°扫描角度。如果扫描角度为负值,则扫描角度将视为扫描角度模数360
圆弧顺时针方向绘制。 0度的角度对应于0度的几何角度(手表上的3点钟)。
| 参数(Parameters) | |
|---|---|
left |
float
|
top |
float
|
right |
float
|
bottom |
float
|
startAngle |
float: Starting angle (in degrees) where the arc begins |
sweepAngle |
float: Sweep angle (in degrees) measured clockwise |
useCenter |
boolean: If true, include the center of the oval in the arc, and close it if it is being stroked. This will draw a wedge |
paint |
Paint: The paint used to draw the arc |
void drawArc (RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint paint)
绘制指定的弧,该弧将被缩放以适合指定的椭圆内。
如果起始角度为负值或> = 360,则将起始角度视为模数360的起始角度。
如果扫掠角> = 360,则完全绘制椭圆。 请注意,这与SkPath :: arcTo略有不同,SkPath :: arcTo将模拟360°扫描角度。如果扫描角度为负值,则扫描角度将视为扫描角度模数360
圆弧顺时针方向绘制。 0度的角度对应于0度的几何角度(手表上的3点钟)。
| 参数(Parameters) | |
|---|---|
oval |
RectF: The bounds of oval used to define the shape and size of the arc |
startAngle |
float: Starting angle (in degrees) where the arc begins |
sweepAngle |
float: Sweep angle (in degrees) measured clockwise |
useCenter |
boolean: If true, include the center of the oval in the arc, and close it if it is being stroked. This will draw a wedge |
paint |
Paint: The paint used to draw the arc |
void drawBitmap (Bitmap bitmap, Matrix matrix, Paint paint)
使用指定的矩阵绘制位图。
| 参数(Parameters) | |
|---|---|
bitmap |
Bitmap: The bitmap to draw |
matrix |
Matrix: The matrix used to transform the bitmap when it is drawn |
paint |
Paint: May be null. The paint used to draw the bitmap |
void drawBitmap (int[] colors,
int offset,
int stride,
float x,
float y,
int width,
int height,
boolean hasAlpha,
Paint paint)
此方法在API级别21中已弃用。
每次调用此方法时,使用hardware accelerated画布都需要彩色缓冲区内容的内部副本。 使用位图可避免此副本,并允许应用程序更明确地控制像素数据的寿命和副本。
将指定的颜色数组视为位图,然后绘制它。 这给出了与首先从数组创建位图并绘制它相同的结果,但是此方法避免了显式创建位图对象,如果颜色经常变化,该位图对象可能更有效。
| 参数(Parameters) | |
|---|---|
colors |
int: Array of colors representing the pixels of the bitmap |
offset |
int: Offset into the array of colors for the first pixel |
stride |
int: The number of colors in the array between rows (must be >= width or <= -width). |
x |
float: The X coordinate for where to draw the bitmap |
y |
float: The Y coordinate for where to draw the bitmap |
width |
int: The width of the bitmap |
height |
int: The height of the bitmap |
hasAlpha |
boolean: True if the alpha channel of the colors contains valid values. If false, the alpha byte is ignored (assumed to be 0xFF for every pixel). |
paint |
Paint: May be null. The paint used to draw the bitmap |
void drawBitmap (int[] colors,
int offset,
int stride,
int x,
int y,
int width,
int height,
boolean hasAlpha,
Paint paint)
此方法在API级别21中已弃用。
每次调用此方法时,使用hardware accelerated画布都需要彩色缓冲区内容的内部副本。 使用位图可避免此副本,并允许应用程序更明确地控制像素数据的寿命和副本。
旧版本的drawBitmap(int []颜色,...),它为x,y带来了整数
| 参数(Parameters) | |
|---|---|
colors |
int
|
offset |
int
|
stride |
int
|
x |
int
|
y |
int
|
width |
int
|
height |
int
|
hasAlpha |
boolean
|
paint |
Paint
|
void drawBitmap (Bitmap bitmap, Rect src, Rect dst, Paint paint)
绘制指定的位图,自动缩放/翻译以填充目标矩形。 如果源矩形不为空,则指定要绘制的位图的子集。
注意:如果paint中包含一个可以生成超出位图原始宽度/高度的遮罩(例如BlurMaskFilter)的遮罩过滤器,则该位图将被绘制,就好像它处于CLAMP模式的着色器中一样。 因此,原始宽度/高度之外的颜色将是边缘颜色的复制。
该函数忽略与位图相关的密度 。 这是因为源和目标矩形坐标空间处于其各自的密度,所以必须已经具有适当的缩放因子。
| 参数(Parameters) | |
|---|---|
bitmap |
Bitmap: The bitmap to be drawn |
src |
Rect: May be null. The subset of the bitmap to be drawn |
dst |
Rect: The rectangle that the bitmap will be scaled/translated to fit into |
paint |
Paint: May be null. The paint used to draw the bitmap |
void drawBitmap (Bitmap bitmap, float left, float top, Paint paint)
使用由当前矩阵转换的指定颜料绘制指定的位图,其顶部/左侧角在(x,y)处。
注意:如果paint中包含一个可以生成超出位图原始宽度/高度的遮罩(例如BlurMaskFilter)的遮罩过滤器,则该位图将被绘制,就好像它处于CLAMP模式的着色器中一样。 因此,原始宽度/高度之外的颜色将是边缘颜色的复制。
如果位图和画布具有不同的密度,则此功能将负责自动缩放位图以与画布相同的密度进行绘制。
| 参数(Parameters) | |
|---|---|
bitmap |
Bitmap: The bitmap to be drawn |
left |
float: The position of the left side of the bitmap being drawn |
top |
float: The position of the top side of the bitmap being drawn |
paint |
Paint: The paint used to draw the bitmap (may be null) |
void drawBitmap (Bitmap bitmap, Rect src, RectF dst, Paint paint)
绘制指定的位图,自动缩放/翻译以填充目标矩形。 如果源矩形不为空,则指定要绘制的位图的子集。
注意:如果paint中包含一个可以生成超出位图原始宽度/高度的遮罩(例如BlurMaskFilter)的遮罩过滤器,则该位图将被绘制,就好像它处于CLAMP模式的着色器中一样。 因此,原始宽度/高度之外的颜色将是边缘颜色的复制。
该函数忽略与位图相关的密度 。 这是因为源和目标矩形坐标空间处于其各自的密度,所以必须已经具有适当的缩放因子。
| 参数(Parameters) | |
|---|---|
bitmap |
Bitmap: The bitmap to be drawn |
src |
Rect: May be null. The subset of the bitmap to be drawn |
dst |
RectF: The rectangle that the bitmap will be scaled/translated to fit into |
paint |
Paint: May be null. The paint used to draw the bitmap |
void drawBitmapMesh (Bitmap bitmap, int meshWidth, int meshHeight, float[] verts, int vertOffset, int[] colors, int colorOffset, Paint paint)
通过网格绘制位图,其中网格顶点均匀分布在位图中。 有meshWidth + 1个顶点,而meshHeight + 1个顶点向下。 verts数组以行优先顺序访问,以便第一个meshWidth + 1顶点从左到右分布在位图顶部。 这个方法的更一般的版本是drawVertices()。
| 参数(Parameters) | |
|---|---|
bitmap |
Bitmap: The bitmap to draw using the mesh |
meshWidth |
int: The number of columns in the mesh. Nothing is drawn if this is 0 |
meshHeight |
int: The number of rows in the mesh. Nothing is drawn if this is 0 |
verts |
float: Array of x,y pairs, specifying where the mesh should be drawn. There must be at least (meshWidth+1) * (meshHeight+1) * 2 + vertOffset values in the array |
vertOffset |
int: Number of verts elements to skip before drawing |
colors |
int: May be null. Specifies a color at each vertex, which is interpolated across the cell, and whose values are multiplied by the corresponding bitmap colors. If not null, there must be at least (meshWidth+1) * (meshHeight+1) + colorOffset values in the array. |
colorOffset |
int: Number of color elements to skip before drawing |
paint |
Paint: May be null. The paint used to draw the bitmap |
void drawCircle (float cx,
float cy,
float radius,
Paint paint)
使用指定的绘图绘制指定的圆。 如果半径<= 0,则不会绘制任何内容。 圆形将根据油漆中的样式进行填充或框定。
| 参数(Parameters) | |
|---|---|
cx |
float: The x-coordinate of the center of the cirle to be drawn |
cy |
float: The y-coordinate of the center of the cirle to be drawn |
radius |
float: The radius of the cirle to be drawn |
paint |
Paint: The paint used to draw the circle |
void drawColor (int color)
使用srcover porterduff模式,用指定的颜色填充整个画布的位图(限制为当前剪辑)。
| 参数(Parameters) | |
|---|---|
color |
int: the color to draw onto the canvas |
void drawColor (int color,
PorterDuff.Mode mode)
用指定的颜色和porter-duff xfermode填充整个画布的位图(仅限于当前剪辑)。
| 参数(Parameters) | |
|---|---|
color |
int: the color to draw with |
mode |
PorterDuff.Mode: the porter-duff mode to apply to the color |
void drawLine (float startX,
float startY,
float stopX,
float stopY,
Paint paint)
使用指定的绘图绘制一条具有指定的起点和停止x,y坐标的线段。
请注意,由于一条线总是被“框住”,所以在油漆中风格被忽略。
退化线(长度为0)将不会绘制。
| 参数(Parameters) | |
|---|---|
startX |
float: The x-coordinate of the start point of the line |
startY |
float: The y-coordinate of the start point of the line |
stopX |
float
|
stopY |
float
|
paint |
Paint: The paint used to draw the line |
void drawLines (float[] pts,
int offset,
int count,
Paint paint)
画一系列线条。 每行都来自pts数组中的4个连续值。 因此,要绘制1行,该数组必须包含至少4个值。 这在逻辑上与绘制数组的方式相同:drawLine(pts [0],pts [1],pts [2],pts [3]),后跟drawLine(pts [4],pts [5],pts [ 6],pts [7])等等。
| 参数(Parameters) | |
|---|---|
pts |
float: Array of points to draw [x0 y0 x1 y1 x2 y2 ...] |
offset |
int: Number of values in the array to skip before drawing. |
count |
int: The number of values in the array to process, after skipping "offset" of them. Since each line uses 4 values, the number of "lines" that are drawn is really (count >> 2). |
paint |
Paint: The paint used to draw the points |
void drawLines (float[] pts,
Paint paint)
| 参数(Parameters) | |
|---|---|
pts |
float
|
paint |
Paint
|
void drawOval (float left,
float top,
float right,
float bottom,
Paint paint)
使用指定的绘图绘制指定的椭圆。 椭圆形将根据油漆中的风格填充或框起。
| 参数(Parameters) | |
|---|---|
left |
float
|
top |
float
|
right |
float
|
bottom |
float
|
paint |
Paint
|
void drawOval (RectF oval, Paint paint)
使用指定的绘图绘制指定的椭圆。 椭圆形将根据油漆中的风格填充或框起。
| 参数(Parameters) | |
|---|---|
oval |
RectF: The rectangle bounds of the oval to be drawn |
paint |
Paint
|
void drawPaint (Paint paint)
使用指定的油漆填充整个画布的位图(仅限于当前剪辑)。 这与使用指定的绘画绘制无限大的矩形是等效的(但更快)。
| 参数(Parameters) | |
|---|---|
paint |
Paint: The paint used to draw onto the canvas |
void drawPath (Path path, Paint paint)
使用指定的绘图绘制指定的路径。 路径将根据油漆中的样式进行填充或构图。
| 参数(Parameters) | |
|---|---|
path |
Path: The path to be drawn |
paint |
Paint: The paint used to draw the path |
void drawPicture (Picture picture, Rect dst)
绘制图片,拉伸以适合dst矩形。
| 参数(Parameters) | |
|---|---|
picture |
Picture
|
dst |
Rect
|
void drawPicture (Picture picture, RectF dst)
绘制图片,拉伸以适合dst矩形。
| 参数(Parameters) | |
|---|---|
picture |
Picture
|
dst |
RectF
|
void drawPicture (Picture picture)
保存画布状态,绘制图片并恢复画布状态。 这与picture.draw(canvas)不同,它不执行任何保存/恢复。
注意:这会强制图片在内部调用 endRecording()以准备播放。
| 参数(Parameters) | |
|---|---|
picture |
Picture: The picture to be drawn |
void drawPoint (float x,
float y,
Paint paint)
用于绘制单个点的drawPoints()的帮助器。
| 参数(Parameters) | |
|---|---|
x |
float
|
y |
float
|
paint |
Paint
|
void drawPoints (float[] pts,
int offset,
int count,
Paint paint)
画出一系列点。 每个点都以pts []指定的坐标为中心,其直径由画笔笔触宽度(由画布'CTM变换)指定,特殊处理的笔画宽度为0,总是绘制1个像素(如果启用了抗锯齿功能,则最多为4)。 点的形状由涂料的帽型控制。 形状是一个正方形,除非帽子类型是圆形,在这种情况下,形状是一个圆形。
| 参数(Parameters) | |
|---|---|
pts |
float: Array of points to draw [x0 y0 x1 y1 x2 y2 ...] |
offset |
int: Number of values to skip before starting to draw. |
count |
int: The number of values to process, after skipping offset of them. Since one point uses two values, the number of "points" that are drawn is really (count >> 1). |
paint |
Paint: The paint used to draw the points |
void drawPoints (float[] pts,
Paint paint)
用于drawPoints()的助手,假定您要绘制整个数组
| 参数(Parameters) | |
|---|---|
pts |
float
|
paint |
Paint
|
void drawPosText (String text, float[] pos, Paint paint)
此方法在API级别16中已被弃用。
此方法不支持字形组合和分解,因此不应该用于渲染复杂的脚本。 它也不处理补充字符(例如表情符号)。
在数组中绘制文本,每个字符的原点由pos数组指定。
| 参数(Parameters) | |
|---|---|
text |
String: The text to be drawn |
pos |
float: Array of [x,y] positions, used to position each character |
paint |
Paint: The paint used for the text (e.g. color, size, style) |
void drawPosText (char[] text,
int index,
int count,
float[] pos,
Paint paint)
此方法在API级别16中已被弃用。
此方法不支持字形组合和分解,因此不应该用于渲染复杂的脚本。 它也不处理补充字符(例如表情符号)。
在数组中绘制文本,每个字符的原点由pos数组指定。
| 参数(Parameters) | |
|---|---|
text |
char: The text to be drawn |
index |
int: The index of the first character to draw |
count |
int: The number of characters to draw, starting from index. |
pos |
float: Array of [x,y] positions, used to position each character |
paint |
Paint: The paint used for the text (e.g. color, size, style) |
void drawRGB (int r,
int g,
int b)
使用srcover porterduff模式,用指定的RGB颜色填充整个画布的位图(仅限于当前剪辑)。
| 参数(Parameters) | |
|---|---|
r |
int: red component (0..255) of the color to draw onto the canvas |
g |
int: green component (0..255) of the color to draw onto the canvas |
b |
int: blue component (0..255) of the color to draw onto the canvas |
void drawRect (float left,
float top,
float right,
float bottom,
Paint paint)
使用指定的绘图绘制指定的Rect。 该矩形将根据油漆中的样式进行填充或框定。
| 参数(Parameters) | |
|---|---|
left |
float: The left side of the rectangle to be drawn |
top |
float: The top side of the rectangle to be drawn |
right |
float: The right side of the rectangle to be drawn |
bottom |
float: The bottom side of the rectangle to be drawn |
paint |
Paint: The paint used to draw the rect |
void drawRect (Rect r, Paint paint)
使用指定的Paint绘制指定的Rect。 该矩形将根据油漆中的样式进行填充或框定。
| 参数(Parameters) | |
|---|---|
r |
Rect: The rectangle to be drawn. |
paint |
Paint: The paint used to draw the rectangle |
void drawRect (RectF rect, Paint paint)
使用指定的绘图绘制指定的Rect。 该矩形将根据油漆中的样式进行填充或框定。
| 参数(Parameters) | |
|---|---|
rect |
RectF: The rect to be drawn |
paint |
Paint: The paint used to draw the rect |
void drawRoundRect (RectF rect, float rx, float ry, Paint paint)
使用指定的绘图绘制指定的圆角。 根据油漆中的风格,该圆形将被填充或框住。
| 参数(Parameters) | |
|---|---|
rect |
RectF: The rectangular bounds of the roundRect to be drawn |
rx |
float: The x-radius of the oval used to round the corners |
ry |
float: The y-radius of the oval used to round the corners |
paint |
Paint: The paint used to draw the roundRect |
void drawRoundRect (float left,
float top,
float right,
float bottom,
float rx,
float ry,
Paint paint)
使用指定的绘图绘制指定的圆角。 根据油漆中的风格,该圆形将被填充或框住。
| 参数(Parameters) | |
|---|---|
left |
float
|
top |
float
|
right |
float
|
bottom |
float
|
rx |
float: The x-radius of the oval used to round the corners |
ry |
float: The y-radius of the oval used to round the corners |
paint |
Paint: The paint used to draw the roundRect |
void drawText (CharSequence text, int start, int end, float x, float y, Paint paint)
绘制指定范围的文本,由start / end指定,其原点位于(x,y)指定的Paint中。 根据“绘画”中的“对齐”设置来解释原点。
| 参数(Parameters) | |
|---|---|
text |
CharSequence: The text to be drawn |
start |
int: The index of the first character in text to draw |
end |
int: (end - 1) is the index of the last character in text to draw |
x |
float: The x-coordinate of origin for where to draw the text |
y |
float: The y-coordinate of origin for where to draw the text |
paint |
Paint: The paint used for the text (e.g. color, size, style) |
void drawText (String text, float x, float y, Paint paint)
使用指定的绘图在原点(x,y)处绘制文本。 根据油漆中的对齐设置来解释原点。
| 参数(Parameters) | |
|---|---|
text |
String: The text to be drawn |
x |
float: The x-coordinate of the origin of the text being drawn |
y |
float: The y-coordinate of the baseline of the text being drawn |
paint |
Paint: The paint used for the text (e.g. color, size, style) |
void drawText (String text, int start, int end, float x, float y, Paint paint)
使用指定的绘图在原点(x,y)处绘制文本。 根据油漆中的对齐设置来解释原点。
| 参数(Parameters) | |
|---|---|
text |
String: The text to be drawn |
start |
int: The index of the first character in text to draw |
end |
int: (end - 1) is the index of the last character in text to draw |
x |
float: The x-coordinate of the origin of the text being drawn |
y |
float: The y-coordinate of the baseline of the text being drawn |
paint |
Paint: The paint used for the text (e.g. color, size, style) |
void drawText (char[] text,
int index,
int count,
float x,
float y,
Paint paint)
使用指定的绘图在原点(x,y)处绘制文本。 根据油漆中的对齐设置来解释原点。
| 参数(Parameters) | |
|---|---|
text |
char: The text to be drawn |
index |
int
|
count |
int
|
x |
float: The x-coordinate of the origin of the text being drawn |
y |
float: The y-coordinate of the baseline of the text being drawn |
paint |
Paint: The paint used for the text (e.g. color, size, style) |
void drawTextOnPath (String text, Path path, float hOffset, float vOffset, Paint paint)
沿着指定的路径使用指定的绘图绘制文本,原点位于(x,y)处。 油漆的“对齐”设置确定沿着路径开始文本的位置。
| 参数(Parameters) | |
|---|---|
text |
String: The text to be drawn |
path |
Path: The path the text should follow for its baseline |
hOffset |
float: The distance along the path to add to the text's starting position |
vOffset |
float: The distance above(-) or below(+) the path to position the text |
paint |
Paint: The paint used for the text (e.g. color, size, style) |
void drawTextOnPath (char[] text,
int index,
int count,
Path path,
float hOffset,
float vOffset,
Paint paint)
沿着指定的路径使用指定的绘图绘制文本,原点位于(x,y)处。 油漆的“对齐”设置确定沿着路径开始文本的位置。
| 参数(Parameters) | |
|---|---|
text |
char: The text to be drawn |
index |
int
|
count |
int
|
path |
Path: The path the text should follow for its baseline |
hOffset |
float: The distance along the path to add to the text's starting position |
vOffset |
float: The distance above(-) or below(+) the path to position the text |
paint |
Paint: The paint used for the text (e.g. color, size, style) |
void drawTextRun (char[] text,
int index,
int count,
int contextIndex,
int contextCount,
float x,
float y,
boolean isRtl,
Paint paint)
在单一方向上绘制一段文本,并带有用于复杂文本整形的可选上下文。
详情请参阅drawTextRun(CharSequence, int, int, int, int, float, float, boolean, Paint) 。 此方法使用字符数组而不是CharSequence来表示字符串。 而且,为了与在drawText(char[], int, int, float, float, Paint)中建立的模式一致,在该方法中使用count和contextCount而不是结束位置的偏移; count = end - start, contextCount = contextEnd - contextStart 。
| 参数(Parameters) | |
|---|---|
text |
char: the text to render |
index |
int: the start of the text to render |
count |
int: the count of chars to render |
contextIndex |
int: the start of the context for shaping. Must be no greater than index. |
contextCount |
int: the number of characters in the context for shaping. contexIndex + contextCount must be no less than index + count. |
x |
float: the x position at which to draw the text |
y |
float: the y position at which to draw the text |
isRtl |
boolean: whether the run is in RTL direction |
paint |
Paint: the paint |
void drawTextRun (CharSequence text, int start, int end, int contextStart, int contextEnd, float x, float y, boolean isRtl, Paint paint)
在单一方向上绘制一段文本,并带有用于复杂文本整形的可选上下文。
文本运行包括文本中从start到end的字符。 另外,范围contextStart到contextEnd被用作复杂文本整形目的的上下文,例如阿拉伯文本可能根据其旁边的文本有不同的形状。
范围contextStart..contextEnd之外的所有文本都将被忽略。 start和end之间的文字将被布置和绘制。
运行的方向由isRtl明确指定。 因此,这种方法仅适用于单一方向的运行。 文本的对齐取决于Paint的TextAlign值。 此外, 0 <= contextStart <= start <= end <= contextEnd <= text.length必须持有进入。
另请参阅getRunAdvance(char[], int, int, int, int, boolean, int)以获取测量文本的相应方法; 绘制文本的前进宽度与从该方法获得的值相匹配。
| 参数(Parameters) | |
|---|---|
text |
CharSequence: the text to render |
start |
int: the start of the text to render. Data before this position can be used for shaping context. |
end |
int: the end of the text to render. Data at or after this position can be used for shaping context. |
contextStart |
int: the index of the start of the shaping context |
contextEnd |
int: the index of the end of the shaping context |
x |
float: the x position at which to draw the text |
y |
float: the y position at which to draw the text |
isRtl |
boolean: whether the run is in RTL direction |
paint |
Paint: the paint |
void drawVertices (Canvas.VertexMode mode, int vertexCount, float[] verts, int vertOffset, float[] texs, int texOffset, int[] colors, int colorOffset, short[] indices, int indexOffset, int indexCount, Paint paint)
绘制顶点数组,解释为三角形(基于模式)。 verts数组是必需的,并为每个顶点指定x,y对。 如果texs非空,则它用于指定在每个顶点使用的着色器坐标中的坐标(在这种情况下,该着色器必须具有着色器)。 如果没有tex数组,但有一个颜色数组,则每个颜色都会以渐变方式在相应的三角形内插。 如果tex和色彩数组都存在,则它们的行为与以前一样,但是每个像素的结果颜色是将着色器中的颜色与颜色渐变相乘的结果。 indices数组是可选的,但是如果它存在,那么它用于指定每个三角形的索引,而不是按顺序遍历数组。
| 参数(Parameters) | |
|---|---|
mode |
Canvas.VertexMode: How to interpret the array of vertices |
vertexCount |
int: The number of values in the vertices array (and corresponding texs and colors arrays if non-null). Each logical vertex is two values (x, y), vertexCount must be a multiple of 2. |
verts |
float: Array of vertices for the mesh |
vertOffset |
int: Number of values in the verts to skip before drawing. |
texs |
float: May be null. If not null, specifies the coordinates to sample into the current shader (e.g. bitmap tile or gradient) |
texOffset |
int: Number of values in texs to skip before drawing. |
colors |
int: May be null. If not null, specifies a color for each vertex, to be interpolated across the triangle. |
colorOffset |
int: Number of values in colors to skip before drawing. |
indices |
short: If not null, array of indices to reference into the vertex (texs, colors) array. |
indexOffset |
int
|
indexCount |
int: number of entries in the indices array (if not null). |
paint |
Paint: Specifies the shader to use if the texs array is non-null. |
boolean getClipBounds (Rect bounds)
返回bounds参数中当前剪辑的边界(以本地坐标表示),如果非空,则返回true。 这在类似于quickReject的方法中可能很有用,因为它告诉你在这些边界之外的绘图将被剪掉。
| 参数(Parameters) | |
|---|---|
bounds |
Rect: Return the clip bounds here. If it is null, ignore it but still return true if the current clip is non-empty. |
| 返回(Returns) | |
|---|---|
boolean |
true if the current clip is non-empty. |
Rect getClipBounds ()
检索当前剪辑的边界(以本地坐标)。
| 返回(Returns) | |
|---|---|
Rect |
the clip bounds, or [0, 0, 0, 0] if the clip is empty. |
int getDensity ()
返回画布的目标密度。 默认密度来源于其背景位图的密度,如果不存在, DENSITY_NONE 。
| 返回(Returns) | |
|---|---|
int |
Returns the current target density of the canvas, which is used to determine the scaling factor when drawing a bitmap into it. |
也可以看看:
int getHeight ()
返回当前绘图图层的高度
| 返回(Returns) | |
|---|---|
int |
the height of the current drawing layer |
Matrix getMatrix ()
此方法在API级别16中已被弃用。
Hardware accelerated画布在传递给View或Drawable时可能具有任何矩阵,因为它是实现定义在层次结构中创建画布的地方。 建议在这种情况下绘制与当前矩阵无关的内容,或者在画布外跟踪相关的变换状态。
用画布的当前变换矩阵的副本返回一个新矩阵。
| 返回(Returns) | |
|---|---|
Matrix |
|
void getMatrix (Matrix ctm)
此方法在API级别16中已被弃用。
Hardware accelerated画布在传递给View或Drawable时可能具有任何矩阵,因为它是在层次结构中创建画布的实现定义。 建议在这种情况下绘制与当前矩阵无关的内容,或者在画布外跟踪相关的变换状态。
用ctm返回当前的变换矩阵。 这不会改变画布中的矩阵,而只是返回它的副本。
| 参数(Parameters) | |
|---|---|
ctm |
Matrix
|
int getMaximumBitmapHeight ()
返回使用此画布绘制的位图的最大允许高度。 尝试使用高于此值的位图进行绘制将导致错误。
| 返回(Returns) | |
|---|---|
int |
|
也可以看看:
int getMaximumBitmapWidth ()
返回使用此画布绘制的位图的最大允许宽度。 尝试绘制比这个值更宽的位图会导致错误。
| 返回(Returns) | |
|---|---|
int |
|
也可以看看:
int getSaveCount ()
返回Canvas专用堆栈上矩阵/剪辑状态的数量。 这将等于#save()调用 - #restore()调用。
| 返回(Returns) | |
|---|---|
int |
|
int getWidth ()
返回当前绘图图层的宽度
| 返回(Returns) | |
|---|---|
int |
the width of the current drawing layer |
boolean isHardwareAccelerated ()
指示此Canvas是否使用硬件加速。 请注意,此方法并未定义可以或不可以使用哪种类型的硬件加速。
| 返回(Returns) | |
|---|---|
boolean |
True if drawing operations are hardware accelerated, false otherwise. |
boolean isOpaque ()
如果当前图层绘制的设备不透明(即不支持每像素alpha),则返回true。
| 返回(Returns) | |
|---|---|
boolean |
true if the device that the current layer draws into is opaque |
boolean quickReject (float left,
float top,
float right,
float bottom,
Canvas.EdgeType type)
如果指定矩形在被当前矩阵转换后完全位于当前剪辑之外,则返回true。 调用这个函数来检查你想要绘制的区域是否被剪掉(因此你可以跳过绘制调用)。
| 参数(Parameters) | |
|---|---|
left |
float: The left side of the rectangle to compare with the current clip |
top |
float: The top of the rectangle to compare with the current clip |
right |
float: The right side of the rectangle to compare with the current clip |
bottom |
float: The bottom of the rectangle to compare with the current clip |
type |
Canvas.EdgeType: AA if the path should be considered antialiased, since that means it may affect a larger area (more pixels) than non-antialiased (BW). |
| 返回(Returns) | |
|---|---|
boolean |
true if the rect (transformed by the canvas' matrix) does not intersect with the canvas' clip |
boolean quickReject (Path path, Canvas.EdgeType type)
如果指定的路径在被当前矩阵转换后完全位于当前剪辑之外,则返回true。 调用这个函数来检查你想要绘制的区域是否被剪掉(因此你可以跳过绘制调用)。 注意:对于速度,即使路径本身可能不与剪辑相交(即路径边界相交,但路径不相交),它也可能返回错误。
| 参数(Parameters) | |
|---|---|
path |
Path: The path to compare with the current clip |
type |
Canvas.EdgeType: AA if the path should be considered antialiased, since that means it may affect a larger area (more pixels) than non-antialiased (BW). |
| 返回(Returns) | |
|---|---|
boolean |
true if the path (transformed by the canvas' matrix) does not intersect with the canvas' clip |
boolean quickReject (RectF rect, Canvas.EdgeType type)
如果指定矩形在被当前矩阵转换后完全位于当前剪辑之外,则返回true。 调用这个函数来检查你想要绘制的区域是否被剪掉(因此你可以跳过绘制调用)。
| 参数(Parameters) | |
|---|---|
rect |
RectF: the rect to compare with the current clip |
type |
Canvas.EdgeType: AA if the path should be considered antialiased, since that means it may affect a larger area (more pixels) than non-antialiased (BW). |
| 返回(Returns) | |
|---|---|
boolean |
true if the rect (transformed by the canvas' matrix) does not intersect with the canvas' clip |
void restore ()
此调用将先前调用save(),并用于从上次保存调用后删除对矩阵/剪辑状态的所有修改。 调用restore()比调用save()多次是错误的。
void restoreToCount (int saveCount)
有效的方式来弹出任何调用save()之后发生的保存计数达到saveCount。 saveCount小于1时出错。示例:int count = canvas.save(); ... //更多的调用潜在的保存()canvas.restoreToCount(count); //现在画布回到初始//调用save()之前的状态。
| 参数(Parameters) | |
|---|---|
saveCount |
int: The save level to restore to. |
void rotate (float degrees,
float px,
float py)
用指定的旋转预先缩放当前矩阵。
| 参数(Parameters) | |
|---|---|
degrees |
float: The amount to rotate, in degrees |
px |
float: The x-coord for the pivot point (unchanged by the rotation) |
py |
float: The y-coord for the pivot point (unchanged by the rotation) |
void rotate (float degrees)
用指定的旋转预先缩放当前矩阵。
| 参数(Parameters) | |
|---|---|
degrees |
float: The amount to rotate, in degrees |
int save (int saveFlags)
基于saveFlags,可以将当前矩阵和剪辑保存到私有堆栈中。
注意:如果可能,请使用无参数save()。 这比单独禁止使用此方法保存矩阵或剪辑更简单快捷。
后续调用translate,scale,rotate,skew,concat或clipRect,clipPath将像往常一样操作,但是当调用restore()时,这些调用将被忘记,并且save()将被恢复。
| 参数(Parameters) | |
|---|---|
saveFlags |
int: flag bits that specify which parts of the Canvas state to save/restore |
| 返回(Returns) | |
|---|---|
int |
The value to pass to restoreToCount() to balance this save() |
int save ()
保存当前矩阵并剪辑到私有堆栈上。
后续调用translate,scale,rotate,skew,concat或clipRect,clipPath将像往常一样操作,但是当调用restore()时,这些调用将被忘记,并且save()将被恢复。
| 返回(Returns) | |
|---|---|
int |
The value to pass to restoreToCount() to balance this save() |
int saveLayer (float left,
float top,
float right,
float bottom,
Paint paint)
saveLayer的便利性(左,上,右,下,油漆, ALL_SAVE_FLAG )
| 参数(Parameters) | |
|---|---|
left |
float
|
top |
float
|
right |
float
|
bottom |
float
|
paint |
Paint
|
| 返回(Returns) | |
|---|---|
int |
|
int saveLayer (RectF bounds, Paint paint, int saveFlags)
它的行为与save()相同,但是它还分配并将图形重定向到离屏位图。
注意:这种方法非常昂贵,所含内容的渲染成本高于两倍。 避免使用这种方法,尤其是如果所提供的范围是大的,或者如果CLIP_TO_LAYER_SAVE_FLAG从省略saveFlags参数。 建议在View上使用hardware layer以应用xfermode,颜色过滤器或alpha,因为它比此方法执行得更好。
所有的绘图调用都被定向到一个新分配的离屏位图。 只有在对restore()进行平衡调用时,屏幕外缓冲区才会回退到Canvas的当前目标(屏幕,目标位图或上一层)。
在调用restore()时, Xfermode离屏位图时应用Paint - alpha和 ColorFilter属性。
| 参数(Parameters) | |
|---|---|
bounds |
RectF: May be null. The maximum size the offscreen bitmap needs to be (in local coordinates) |
paint |
Paint: This is copied, and is applied to the offscreen when restore() is called. |
saveFlags |
int: see _SAVE_FLAG constants, generally ALL_SAVE_FLAG is recommended for performance reasons. |
| 返回(Returns) | |
|---|---|
int |
value to pass to restoreToCount() to balance this save() |
int saveLayer (RectF bounds, Paint paint)
方便saveLayer(边界,油漆, ALL_SAVE_FLAG )
| 参数(Parameters) | |
|---|---|
bounds |
RectF
|
paint |
Paint
|
| 返回(Returns) | |
|---|---|
int |
|
int saveLayer (float left,
float top,
float right,
float bottom,
Paint paint,
int saveFlags)
saveLayer()的帮助版本取4个值而不是RectF。
| 参数(Parameters) | |
|---|---|
left |
float
|
top |
float
|
right |
float
|
bottom |
float
|
paint |
Paint
|
saveFlags |
int
|
| 返回(Returns) | |
|---|---|
int |
|
int saveLayerAlpha (float left,
float top,
float right,
float bottom,
int alpha,
int saveFlags)
saveLayerAlpha()的帮助器,取4个值而不是RectF。
| 参数(Parameters) | |
|---|---|
left |
float
|
top |
float
|
right |
float
|
bottom |
float
|
alpha |
int
|
saveFlags |
int
|
| 返回(Returns) | |
|---|---|
int |
|
int saveLayerAlpha (RectF bounds, int alpha, int saveFlags)
它的行为与save()相同,但是它还分配并将图形重定向到离屏位图。
注意:这种方法非常昂贵,所含内容的渲染成本高于两倍。 避免使用这种方法,尤其是如果所提供的范围是大的,或者如果CLIP_TO_LAYER_SAVE_FLAG从省略saveFlags参数。 建议在View上使用hardware layer以应用xfermode,颜色过滤器或alpha,因为它比此方法执行得更好。
所有的绘图调用都被定向到一个新分配的离屏位图。 只有在对restore()进行平衡调用时,屏幕外缓冲区才会回退到Canvas的当前目标(屏幕,目标位图或上一层)。
当调用restore()时, alpha离屏位图时将应用 alpha参数。
| 参数(Parameters) | |
|---|---|
bounds |
RectF: The maximum size the offscreen bitmap needs to be (in local coordinates) |
alpha |
int: The alpha to apply to the offscreen when it is drawn during restore() |
saveFlags |
int: see _SAVE_FLAG constants, generally ALL_SAVE_FLAG is recommended for performance reasons. |
| 返回(Returns) | |
|---|---|
int |
value to pass to restoreToCount() to balance this call |
int saveLayerAlpha (float left,
float top,
float right,
float bottom,
int alpha)
saveLayerAlpha的帮助器(左,上,右,下,alpha, ALL_SAVE_FLAG )
| 参数(Parameters) | |
|---|---|
left |
float
|
top |
float
|
right |
float
|
bottom |
float
|
alpha |
int
|
| 返回(Returns) | |
|---|---|
int |
|
int saveLayerAlpha (RectF bounds, int alpha)
saveLayerAlpha的便利性(界限,alpha, ALL_SAVE_FLAG )
| 参数(Parameters) | |
|---|---|
bounds |
RectF
|
alpha |
int
|
| 返回(Returns) | |
|---|---|
int |
|
void scale (float sx,
float sy,
float px,
float py)
用指定的比例预先缩放当前矩阵。
| 参数(Parameters) | |
|---|---|
sx |
float: The amount to scale in X |
sy |
float: The amount to scale in Y |
px |
float: The x-coord for the pivot point (unchanged by the scale) |
py |
float: The y-coord for the pivot point (unchanged by the scale) |
void scale (float sx,
float sy)
用指定的比例预先缩放当前矩阵。
| 参数(Parameters) | |
|---|---|
sx |
float: The amount to scale in X |
sy |
float: The amount to scale in Y |
void setBitmap (Bitmap bitmap)
指定要绘制的画布的位图。 除当前矩阵和剪辑堆栈之外,所有画布状态(例如图层,过滤器和保存/恢复堆栈)都将重置。 另外,作为副作用,画布的目标密度被更新以匹配位图的密度。
| 参数(Parameters) | |
|---|---|
bitmap |
Bitmap: Specifies a mutable bitmap for the canvas to draw into. |
也可以看看:
void setDensity (int density)
指定此Canvas的支持位图的密度。 这会通过Bitmap.setDensity(int)修改画布本身的目标密度以及其背景位图的密度。
| 参数(Parameters) | |
|---|---|
density |
int: The new target density of the canvas, which is used to determine the scaling factor when drawing a bitmap into it. Use DENSITY_NONE to disable bitmap scaling. |
也可以看看:
void setDrawFilter (DrawFilter filter)
| 参数(Parameters) | |
|---|---|
filter |
DrawFilter
|
void setMatrix (Matrix matrix)
用指定的矩阵完全替换当前矩阵。 如果矩阵参数为空,则将当前矩阵重置为标识。 注:建议使用concat(Matrix) , scale(float, float) , translate(float, float)和rotate(float)采用这个方法。
| 参数(Parameters) | |
|---|---|
matrix |
Matrix: The matrix to replace the current matrix with. If it is null, set the current matrix to identity. |
也可以看看:
void skew (float sx,
float sy)
用指定的偏斜对当前矩阵进行预先扫描。
| 参数(Parameters) | |
|---|---|
sx |
float: The amount to skew in X |
sy |
float: The amount to skew in Y |
void translate (float dx,
float dy)
用指定的转换对当前矩阵进行预处理
| 参数(Parameters) | |
|---|---|
dx |
float: The distance to translate in X |
dy |
float: The distance to translate in Y |