本文主要是介绍Android paint的基本用法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
转载:http://www.cnblogs.com/hexiaochun/archive/2012/10/08/2715324.html //画布绘图的一些应用 //画一个点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 paint的基本用法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!