//画布绘图的一些应用
//画一个点 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);
android 基本的画图方法
最新推荐文章于 2024-05-01 18:04:23 发布