Paint与Canvas

画笔常用属性

画笔的常用属性包括:颜色、透明度、样式、字体属性等

//颜色与透明度
paint.setColor(Color.GREEN);
paint.setARGB(255, 255, 0, 255);
//消除锯齿
paint.setAntiAlias(true);
//设置空心风格
paint.setStyle(Paint.Style.STROKE);
//设置画空心圆的画笔宽度
paint.setStrokeWidth(10);
//文字大小
paint.setTextSize(20);
//文字粗体
paint.setFakeBoldText(true);
//斜体,参数为倾斜角度
paint.setTextSkewX(45);

画布常用属性

//画矩形
canvas.drawRect(100, 100, 300, 400, paint);
//画圆
canvas.drawCircle(100, 700, 100, paint);
//画圆角矩形
RectF rectF = new RectF(10, 200, 60, 250);
canvas.drawRoundRect(rectF, 10, 10, paint);
//画椭圆
RectF oval = new RectF(100, 150, 180, 200);
canvas.drawOval(oval, paint);
//画扇形
RectF s = new RectF(300, 250, 400, 350);
canvas.drawArc(s,0, 90, true,paint);
//画弧
RectF h = new RectF(400, 250, 500, 350);
canvas.drawArc(h, 0, -90, false, paint);
//画文本
paint.setTextSize(50);
paint.setStyle(Paint.Style.FILL);
paint.setFakeBoldText(false);
paint.setTextAlign(Paint.Align.CENTER);
canvas.drawText("text", sx, sy, paint);
//获取文本所占区域
Rect textBound = new Rect();
paint.getTextBounds(str,0,str.length(),textBound);
//textBound可以得到参考点为为默认的(0,0)的文本区域
int x= (int) (progressRectF.centerX()-textBound.centerX());
int y = (int) (progressRectF.centerY()-textBound.centerY());
//画轨迹
Path path = new Path();
path.moveTo(x,y);
path.quadTo(x1, y1, x2, y2);
canvas.drawPath(path, paint);
//画图
BitmapDrawable bd = (BitmapDrawable) context.getResources().
        getDrawable(R.drawable.mm04);
Bitmap bitmap = bd.,getBitmap();
canvas.drawBitmap(bitmap, 0, 0, null);
//图像变换,多个变换相加会覆盖,想叠加用post
Matrix matrix = new Matrix();
//旋转
matrix.setRotate(30, bitmap.getWidth() / 2, bitmap.getHeight() / 2);
//平移
matrix.postTranslate(50, 100);
//缩放
matrix.postScale(2, 2);
//画图
canvas.drawBitmap(bitmap, matrix, null);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值