您的位置:首页 > 移动开发 > Android开发

android-graphics--Canvas译

2014-12-16 23:20 281 查看

android.graphics

类Canvas

相当于画布,控制着绘图的回调,为了画出东西,必须有4个基本组件:控制容纳像素的位图,一个主控绘制回调的画布(用于写位图),

绘图原语(如矩形,路径,文本),用于绘制的画笔。

嵌套类摘要
staticclass
Canvas.EdgeType
边缘类型
staticclass
Canvas.VertexMode
顶点模式,

TRIANGLES三角形,
TRIANGLE_STRIP去除三角形,TRIANGLE_FAN成扇形散开的三角形


字段介绍:

MATRIX_SAVE_FLAG

publicstaticfinalintMATRIX_SAVE_FLAG当restore()被回调时恢复当前的矩阵;

CLIP_SAVE_FLAG

[code]publicstaticfinalintCLIP_SAVE_FLAG当restore()被回调时恢复当前的裁剪;

HAS_ALPHA_LAYER_SAVE_FLAG

[code]publicstaticfinalintHAS_ALPHA_LAYER_SAVE_FLAG图层需要的每一个像素的alpha;

FULL_COLOR_LAYER_SAVE_FLAG

publicstaticfinalintFULL_COLOR_LAYER_SAVE_FLAG图层需要的每一个颜色组件的8位值;
[code]

CLIP_TO_LAYER_SAVE_FLAG

publicstaticfinalintCLIP_TO_LAYER_SAVE_FLAG图层裁剪的边界;

ALL_SAVE_FLAG

publicstaticfinalintALL_SAVE_FLAG当restore()回调时恢复所有的标记位;
构造方法详细信息

Canvas

publicCanvas()构造空的画布,使用setBitmap填充指定的位图到画布;

Canvas

publicCanvas(Bitmapbitmap)使用指定的位图填充的画布,位图必须可变;

Canvas

publicCanvas(GLgl)使用指定的gl上下文构造画布,所有通过画布的绘制都将重定向到opengl中,注意:某些功能可能在这种模式下不支持(如有些GL的实现可能不支持抗锯齿或某些像ColorMatrix或影响某些Xfermodes)。然而,在这些情况下是不会抛出异常的。
方法详细:

getGL

publicGLgetGL()返回画布分配的GL对象,如果不支持GL就返回null;

freeGlCaches

publicstaticvoidfreeGlCaches()释放GL缓存,

setBitmap

[code]publicvoidsetBitmap(Bitmapbitmap)

setViewport

publicvoidsetViewport(intwidth,
intheight)
如果这是基于GL的画布就设置视窗尺寸。如果不是,这个方法将被忽略,没有异常。

isOpaque

[code]publicbooleanisOpaque()当前设备绘制的图层是否是不透明的(即支不支持alpha);

getWidth

publicintgetWidth()得到当前绘制图层的宽;
[/code]

getHeight

[code]publicintgetHeight()

getDensityScale

publicfloatgetDensityScale()

返回这个画布的密度范围的支持位图的密度大小,表示为一个默认的密度的因素(160dpi)。例如,位图设计为240dpi显示将有一个密度1.5而位图的规模为160dpi密度1.0的规模。

默认是
Bitmap.DENSITY_SCALE_UNKNOWN
.

setDensityScale

publicvoidsetDensityScale(floatdensityScale)


save

publicintsave()

保存当前矩阵在一个私人的堆栈。后续调用平移、缩放、旋转、倾斜、concat、clipRectclipPath都像往常一样运作,但当平衡恢复restore()调用,以上操作将被遗忘,并且这些存在的设置在save()前将被取消。返回保存的数量

save

publicintsave(intsaveFlags)指定保存位;即哪一位被保存,在restore时才恢复;


saveLayer

[code]publicintsaveLayer(RectFbounds,
Paintpaint,
intsaveFlags)
和save()一样,但是额外的它还分配了画面以外的位图,后续所有的绘制回调都直接映射那里,只有当restore()调用时屏幕外的绘制图像才会平移到画布上来(或者前一个图层),后续的平移、旋转等操作都是操作在此副本上,当restore()调用,这个副本就会被删除,前一个矩阵或者裁剪的状态就会恢复。


参数:
bounds
-可能是null。画面以外的位图需要的最大大小(以当地坐标)
paint
-restore()调用时,应用在屏幕外的Paint副本
saveFlags
-see_SAVE_FLAGconstants

saveLayer

publicintsaveLayer(floatleft,
floattop,
floatright,
floatbottom,
Paintpaint,
intsaveFlags)

相当于上面的函数;

saveLayerAlpha

publicintsaveLayerAlpha(RectFbounds,
intalpha,
intsaveFlags)功能类似上面

saveLayerAlpha

publicintsaveLayerAlpha(floatleft,
floattop,
floatright,
floatbottom,
intalpha,
intsaveFlags)


restore

publicvoidrestore()

删除save()后操作的状态,调用次数不能超过save()的次数;

getSaveCount

publicintgetSaveCount()

restoreToCount

publicvoidrestoreToCount(intsaveCount)

translate

publicvoidtranslate(floatdx,
floatdy)

scale

publicvoidscale(floatsx,
floatsy)


scale

publicfinalvoidscale(floatsx,
floatsy,
floatpx,
floatpy)

参数:
sx
-x轴放大的倍数
sy
-TheamounttoscaleinY
px
-x轴放大中心点(旋转也不会改变)
py
-They-coordforthepivotpoint(unchangedbytherotation)

rotate

publicvoidrotate(floatdegrees)

rotate

publicfinalvoidrotate(floatdegrees,
floatpx,
floatpy)

skew

publicvoidskew(floatsx,
floatsy)错切


concat

[code]publicvoidconcat(Matrixmatrix)用指定的矩阵合成当前的矩阵,相当于求并集

setMatrix

publicvoidsetMatrix(Matrixmatrix)

用指定的矩阵完全替换当前的矩阵,如果矩阵参数为null,那么将重置当前矩阵。


getMatrix

publicvoidgetMatrix(Matrixctm)

返回当前画布矩阵的一个副本,对它进行操作并不会改变原矩阵;

getMatrix

publicfinalMatrixgetMatrix()

返回画布当前运动矩阵的一个副本矩阵;

clipRect

publicbooleanclipRect(RectFrect,
Region.Opop)

用指定的矩形裁剪

clipPath

publicbooleanclipPath(Pathpath,
Region.Opop)

用指定的路径进行裁剪;

clipRegion

publicbooleanclipRegion(Regionregion,
Region.Opop)

与clipRect()和clipPath()不同,并不会执行矩阵的变换;

getDrawFilter

publicDrawFiltergetDrawFilter()


setDrawFilter

publicvoidsetDrawFilter(DrawFilterfilter)

quickReject

publicbooleanquickReject(RectFrect,
Canvas.EdgeTypetype)

getClipBounds

publicbooleangetClipBounds(Rectbounds)

getClipBounds

publicfinalRectgetClipBounds()

drawRGB

publicvoiddrawRGB(intr,
intg,
intb)

用指定的RGB色填充整个位图;

drawARGB

publicvoiddrawARGB(inta,
intr,
intg,
intb)

drawColor

publicvoiddrawColor(intcolor)

drawColor

publicvoiddrawColor(intcolor,
PorterDuff.Modemode)


drawPaint

publicvoiddrawPaint(Paintpaint)

用画笔的配置填充画布的位图;

drawPoints

publicvoiddrawPoints(float[]pts,
intoffset,
intcount,
Paintpaint)

画出一系列的点

drawLine

publicvoiddrawLine(floatstartX,
floatstartY,
floatstopX,
floatstopY,
Paintpaint)

drawLines

publicvoiddrawLines(float[]pts,
intoffset,
intcount,
Paintpaint)

画出一系列的线;

drawRect

publicvoiddrawRect(RectFrect,
Paintpaint)

指定大小,画笔画出矩形;

drawOval

publicvoiddrawOval(RectFoval,
Paintpaint)

画出椭圆;

drawCircle

publicvoiddrawCircle(floatcx,
floatcy,
floatradius,
Paintpaint)

画圆;

drawArc

publicvoiddrawArc(RectFoval,
floatstartAngle,
floatsweepAngle,
booleanuseCenter,
Paintpaint)

画弧;

drawRoundRect

publicvoiddrawRoundRect(RectFrect,
floatrx,
floatry,
Paintpaint)

画圆角矩形;

drawPath

publicvoiddrawPath(Pathpath,
Paintpaint)

用指定的路径画;

drawBitmap

publicvoiddrawBitmap(Bitmapbitmap,
floatleft,
floattop,
Paintpaint)

将指定位图绘制;

drawBitmap

publicvoiddrawBitmap(Bitmapbitmap,
Rectsrc,
RectFdst,
Paintpaint)

将指定位图的大小位置画至指定的位置;

drawBitmap

publicvoiddrawBitmap(int[]colors,
intoffset,
intstride,
floatx,
floaty,
intwidth,
intheight,
booleanhasAlpha,
Paintpaint)

drawBitmap

publicvoiddrawBitmap(Bitmapbitmap,
Matrixmatrix,
Paintpaint)

用指定的矩阵将原位图进行绘制;

drawBitmapMesh

publicvoiddrawBitmapMesh(Bitmapbitmap,
intmeshWidth,
intmeshHeight,
float[]verts,
intvertOffset,
int[]colors,
intcolorOffset,
Paintpaint)

位图网;

drawVertices

publicvoiddrawVertices(Canvas.VertexModemode,
intvertexCount,
float[]verts,
intvertOffset,
float[]texs,
inttexOffset,
int[]colors,
intcolorOffset,
short[]indices,
intindexOffset,
intindexCount,
Paintpaint)

drawText

publicvoiddrawText(CharSequencetext,
intstart,
intend,
floatx,
floaty,
Paintpaint)

写字;

drawPosText

publicvoiddrawPosText(char[]text,
intindex,
intcount,
float[]pos,
Paintpaint)


指定位置,数量写字;

drawPicture

publicvoiddrawPicture(Picturepicture)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: