Android图像处理之Canvas
2016-03-23 15:52
399 查看
Canvas的相关函数
clip打头的函数表示对canvas裁剪成指定的形状
void clipPath(Path path)
void clipPath(Path path,Region.op op)
void clipRect(RectF rect,Region.op op)
void clipRect(Rect rect,Region.op op)
void clipRect(int left,int top,int right,int bottom)
void clipRect(float left,float top,float right,float bottom)
void clipRect(RectF rect)
void clipRect(float left,float top,float right,float bottom,Region.op op)
void clipRect(Rect rect)
void clipRegion(Region region)
void clipRegion(Region region,Region.op op)
void concat(Matrix matrix):对canvas进行matrix变换(前乘),变换不可逆
void drawRGB(int red,int green,int blue):对canvas上的bitmap着色
void drawArc(RectF oval,float startAngle,float sweepAngle,boolean useCenter,Paint paint):
画弧,该弧由oval,startAngle,sweepAngle决定,useCenter的作用以下代码和对应的图作说明
void drawBitmap(Bitmap source,Rect src,Rect dst,Paint paint):将source用src进行裁剪,dst决定了source在canvas上的大小和位置
void drawBitmap(Bitmap source,int left ,int top,Paint paint):将source画到canvas上,不缩放也不裁剪,位置由left,top决定
void drawBitmao(Bitmap source,Rect src,RectF dst,Paint paint):
void drawBitmap(Bitmap source,Matrix matrix Paint paint):对source进行matrix变换再画到canvas上,注意从(0,0)开始画
void drawCircle(float dx,float dy,Paint paint):
void drawColor(int color):给bitmap上色
void drawColor(int color,PorterDuff.Mode mode):给bitmap上色,并采用mode的覆盖模式
void drawLine(float startx,float starty,float endx,float endy,Paint paint):
void drawLines(float[] opts,Paint):画多条线,opt每4个值表示一条线,多余的忽略
void drawLines(float[] opts,int offset,int count,Paint paint):offset表示opts的起始索引,count考虑的opts中值的总数
void drawOval(RectF oval,Paint):画椭圆
void drawPath(Path path,Paint,paint):
drawPoint(float[] opts,Piant):
drawPosText(String text,float[] opts,Paint paint):将text写在opts指定的位置上
drawPosText(String text,int start,int count,float[] opts,Paint paint):
drawARBG(int a,int r,int b,int g):
三种画矩形的方式
void drawRect(float left,float top,float right,float bottom,Paint paint):
void drawRect(RectF rect,Paint paint):
void drawRect(Rect rect,Paint paint):
void drawRoundRect(RectF rect,float rx,float ry,Piant paint):画圆角矩形,rect确定矩形,rx,ry确定半径
三种写文本的方式
void drawText(String text,float x,float y,Paint paint):以x,y为起点将text写到bitmap上
void drawText(String text,int start,int end,float x,float y,Paint paint):
void drawText(String text,int start,int count,float x,float y):
void drawTextOnPath(String text,Path path,float hOffset,float vOffSet,Paint):将text画在指定path上,hOffset:文字沿path与起始点偏移的距离,v沿中心偏移的距离
void drawTextOnPath(String text,int start,int count,Path path,float hOffset,float vOffset,Paint paint):
Rect getClipBounds():返回该canvas的矩形边界
int getHeight():与canvas绑定的bitmap的高度
int getWidth():与canvas绑定的bitmap的宽
Canvas的平移、缩放、旋转、倾斜等操作
void rotate(float degree):将canvas以(0,0)为圆心旋转degree
void rotate(float degree,float dx,float dy):将canvas以(dx,dy)旋转degree
void scale(float sx,float sy):
void scale(float sx,float sy,float px,float py):px,py为缩放中心
void skew(float sx,float sy):
void translate(float dx,float sy):
注意canvas的平移、缩放、旋转、倾斜、clip等操作都是不可逆的
Canvas的保存与恢复:
void save():将当前的变换矩阵和裁剪状态压入栈中
void restore():从栈中取出栈顶的画布,并按照栈顶的画布恢复当前画布。
关于canvas的保存与恢复请参考Canvas的变换操作
clip打头的函数表示对canvas裁剪成指定的形状
void clipPath(Path path)
void clipPath(Path path,Region.op op)
void clipRect(RectF rect,Region.op op)
void clipRect(Rect rect,Region.op op)
void clipRect(int left,int top,int right,int bottom)
void clipRect(float left,float top,float right,float bottom)
void clipRect(RectF rect)
void clipRect(float left,float top,float right,float bottom,Region.op op)
void clipRect(Rect rect)
void clipRegion(Region region)
void clipRegion(Region region,Region.op op)
void concat(Matrix matrix):对canvas进行matrix变换(前乘),变换不可逆
void drawRGB(int red,int green,int blue):对canvas上的bitmap着色
void drawArc(RectF oval,float startAngle,float sweepAngle,boolean useCenter,Paint paint):
画弧,该弧由oval,startAngle,sweepAngle决定,useCenter的作用以下代码和对应的图作说明
Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG); canvas.drawArc(100,100,300,500,0,150,true,paint);
Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG); canvas.drawArc(100,100,300,500,0,150,false,paint);
void drawBitmap(Bitmap source,Rect src,Rect dst,Paint paint):将source用src进行裁剪,dst决定了source在canvas上的大小和位置
void drawBitmap(Bitmap source,int left ,int top,Paint paint):将source画到canvas上,不缩放也不裁剪,位置由left,top决定
void drawBitmao(Bitmap source,Rect src,RectF dst,Paint paint):
void drawBitmap(Bitmap source,Matrix matrix Paint paint):对source进行matrix变换再画到canvas上,注意从(0,0)开始画
void drawCircle(float dx,float dy,Paint paint):
void drawColor(int color):给bitmap上色
void drawColor(int color,PorterDuff.Mode mode):给bitmap上色,并采用mode的覆盖模式
void drawLine(float startx,float starty,float endx,float endy,Paint paint):
void drawLines(float[] opts,Paint):画多条线,opt每4个值表示一条线,多余的忽略
void drawLines(float[] opts,int offset,int count,Paint paint):offset表示opts的起始索引,count考虑的opts中值的总数
void drawOval(RectF oval,Paint):画椭圆
void drawPath(Path path,Paint,paint):
drawPoint(float[] opts,Piant):
drawPosText(String text,float[] opts,Paint paint):将text写在opts指定的位置上
drawPosText(String text,int start,int count,float[] opts,Paint paint):
drawARBG(int a,int r,int b,int g):
三种画矩形的方式
void drawRect(float left,float top,float right,float bottom,Paint paint):
void drawRect(RectF rect,Paint paint):
void drawRect(Rect rect,Paint paint):
void drawRoundRect(RectF rect,float rx,float ry,Piant paint):画圆角矩形,rect确定矩形,rx,ry确定半径
三种写文本的方式
void drawText(String text,float x,float y,Paint paint):以x,y为起点将text写到bitmap上
void drawText(String text,int start,int end,float x,float y,Paint paint):
void drawText(String text,int start,int count,float x,float y):
void drawTextOnPath(String text,Path path,float hOffset,float vOffSet,Paint):将text画在指定path上,hOffset:文字沿path与起始点偏移的距离,v沿中心偏移的距离
void drawTextOnPath(String text,int start,int count,Path path,float hOffset,float vOffset,Paint paint):
Rect getClipBounds():返回该canvas的矩形边界
int getHeight():与canvas绑定的bitmap的高度
int getWidth():与canvas绑定的bitmap的宽
Canvas的平移、缩放、旋转、倾斜等操作
void rotate(float degree):将canvas以(0,0)为圆心旋转degree
void rotate(float degree,float dx,float dy):将canvas以(dx,dy)旋转degree
void scale(float sx,float sy):
void scale(float sx,float sy,float px,float py):px,py为缩放中心
void skew(float sx,float sy):
void translate(float dx,float sy):
注意canvas的平移、缩放、旋转、倾斜、clip等操作都是不可逆的
Canvas的保存与恢复:
void save():将当前的变换矩阵和裁剪状态压入栈中
void restore():从栈中取出栈顶的画布,并按照栈顶的画布恢复当前画布。
关于canvas的保存与恢复请参考Canvas的变换操作
相关文章推荐
- 【技术分享】Android应用安全开发之浅谈加密算法的坑
- 打开android studio 时遇到卡顿,任务管理器里有N多个aapt.exe进程情况的解决
- Android_Module用法_和_如何制作自己的Library开源库
- Android应用中使用ViewPager和ViewPager指示器来制作Tab标签
- 解决Android调用系统相机拍照后相片无法在相册中显示问题
- Android的Looper类使用详解
- android 文件上传、下载
- android demo自动开启WiFi
- 如何在mac下安装android sdk
- Android 自定义属性,系统控件扩展
- Android ListView常用小技巧汇总
- Android_Handler详解(一)
- Android 最火的快速开发框架XUtils
- Android实战技巧:深入解析AsyncTask
- 图片压缩小例子
- Android中 Handler使用全解
- Ubuntu下开发Android 环境变量设置
- 实例讲解Android中ViewPager组件的一些进阶使用技巧
- Android高德地图开发流程
- 在Eclipse中关联Android Private Libraries中文件的源代码