android 基本的画图方法

//画布绘图的一些应用
//画一个点 Paint paint=new Paint(); paint.setColor(Color.BLUE); paint.setStrokeWidth(100);//设置点的宽度 Canvas canvas=new Canvas(bitmap); canvas.drawPoint(100, 100, paint); chooseView.setImageBitmap(bitmap); //画一条直线 Paint paint=new Paint(); paint.setColor(Color.BLUE); paint.setStrokeWidth(10);//设置点的宽度 float startX=10; float startY=20; float stopX=100; float stopY=200; Canvas canvas=new Canvas(bitmap); canvas.drawLine(startX, startY, stopX, stopY, paint); chooseView.setImageBitmap(bitmap); //画一个矩形 Paint paint=new Paint(); paint.setColor(Color.GRAY); paint.setStrokeWidth(10); paint.setStyle(Paint.Style.FILL_AND_STROKE); Canvas canvas=new Canvas(bitmap); int left=10; int top=10; int right=100; int bottom=100; Rect rect=new Rect(left, top, right, bottom); canvas.drawRect(rect, paint); // canvas.drawRect(left, top, right, bottom, paint); chooseView.setImageBitmap(bitmap); //椭圆 Paint paint=new Paint(); paint.setColor(Color.RED); paint.setStyle(Paint.Style.STROKE); int left=10; int top=20; int right=60; int bottom=100; RectF oval=new RectF(left, top, right, bottom); Canvas canvas=new Canvas(bitmap); canvas.drawOval(oval, paint); chooseView.setImageBitmap(bitmap); //圆 Paint paint=new Paint(); paint.setColor(Color.BLACK); paint.setStyle(Paint.Style.FILL_AND_STROKE); Canvas canvas=new Canvas(bitmap); int cx=100; int cy=100; int radius=20; canvas.drawCircle(cx, cy, radius, paint); chooseView.setImageBitmap(bitmap); //路径 Paint paint=new Paint(); paint.setColor(Color.BLUE); paint.setStyle(Paint.Style.STROKE); //路 Path path=new Path(); path.moveTo(20, 20); path.lineTo(100, 200); path.lineTo(204, 164); path.lineTo(250, 175); path.lineTo(20, 20); Canvas canvas=new Canvas(bitmap); canvas.drawPath(path, paint); chooseView.setImageBitmap(bitmap); //绘制字体 Paint paint=new Paint(); paint.setColor(Color.YELLOW); paint.setTextSize(40); paint.setTypeface(Typeface.DEFAULT_BOLD);//设置字体 //引用外部字体 //Typeface typeface=Typeface.createFromAsset(getAssets(), "newFont.ttf"); //paint.setTypeface(typeface); Canvas canvas=new Canvas(bitmap); canvas.drawText("fuck you!", 50, 100, paint); chooseView.setImageBitmap(bitmap); //把字画在线上 Paint paint=new Paint(); paint.setColor(Color.CYAN); paint.setTextSize(20); paint.setTypeface(Typeface.DEFAULT); Path path=new Path(); path.moveTo(20, 20); path.lineTo(100, 150); path.lineTo(200, 220); Canvas canvas=new Canvas(bitmap); canvas.drawTextOnPath("Fuck you this text is on path!", path, 0, 0, paint); chooseView.setImageBitmap(bitmap);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值