怎么在Android中使用油漆进行绘图

  介绍

本篇文章给大家分享的是有关怎么在Android中使用油漆进行绘图,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

<强>油漆的使用

使用油漆之前需要初始化

mPaint =, new 油漆();

设置笔(油漆)的颜色和α值:

mPaint.setColor (Color.BLUE);   mPaint.setAlpha (255),

<强>注意:α的范围是[0 . . 255],而不是(0 . . 1),是一个int值。

设置画笔的样式:通过mPaint.setStyle()来设置样式。

, public  enum  Style  {/* *   *,才能Geometry 以及text  drawn  with 却;能够style  will  be , ignoring 所有   *,才能stroke-related  settings 拷贝,油漆。   ,*/,FILL  (0)/* *   *,才能Geometry 以及text  drawn  with 却;能够style  will  be 抚摸,尊重   *才能,从而stroke-related  fields 提醒,油漆。   ,*/,STROKE  (1),/* *   *,才能Geometry 以及text  drawn  with 却;能够style  will  be  both  filled    *,才能stroked  at 从而same ,, respecting 从而stroke-related  fields    *,才能,油漆只却;能够mode 还要give  unexpected  results  if 从而几何学   *,才能is  oriented 逆时针只却;能够restriction  does  not  apply    *,才能either  FILL 或中风。   ,*/,FILL_AND_STROKE  (2);      ,风格(int  nativeInt) {   时间=this.nativeInt 才能;nativeInt;   ,}   ,final  int  nativeInt;   以前,}

总共有三种画笔的样式

填充:填充内容,

中风:描边;

FILL_AND_STROKE:填充内容并描边。

<强>设置画笔的宽度

mPaint.setStrokeWidth (50);

<强>设置画笔的线帽

通过<代码> mPaint。setStrokeCap> ,/* *   ,*,Cap  specifies 从而treatment  for 从而beginning 以及ending    ,* stroked  lines 以及路径只,default  is 对接。   ,*/,public  enum  Cap  {/* *   *才能,从而stroke  ends  with 从而路径,以及does  not  project  beyond 它。   ,*/,BUTT  (0),/* *   *才能,从而stroke  projects  out  as  a 半圆,,with 从而center  at    *,才能最终获得of 从而路径。   ,*/,ROUND  (1),/* *   *才能,从而stroke  projects  out  as  a 广场,with 从而center  at 从而结束   *,才能of 从而路径。   ,*/,SQUARE  (2);      ,private 帽(int  nativeInt), {   时间=this.nativeInt 才能;nativeInt;   ,}   ,final  int  nativeInt;   以前,}

对接:没有线帽,默认模式

轮:圆形

广场:方形

<强>三种线帽对比:

, @Override   ,protected  void  onDraw (Canvas 画布),{   ,super.onDraw(画布);   ,mPaint.setColor (Color.BLUE);   ,mPaint.setAlpha (255);      ,//设置画笔的样式   ,mPaint.setStyle (Paint.Style.FILL_AND_STROKE);   ,//画笔的宽度   ,mPaint.setStrokeWidth (50);   ,mPaint.setStrokeCap (Paint.Cap.SQUARE);//方形   ,mPaint.setStrokeJoin (Paint.Join.BEVEL);//直线      ,Path  Path =, new 路径();   ,path.moveTo (100,, 100);   ,path.lineTo (300,, 100);   ,canvas.drawPath(路径,mPaint);      ,mPaint.reset();//重置   ,mPaint.setColor (Color.RED);   ,mPaint.setStyle (Paint.Style.FILL_AND_STROKE);   ,mPaint.setStrokeWidth (50);   ,mPaint.setStrokeCap (Paint.Cap.ROUND);//圆形   ,mPaint.setStrokeJoin (Paint.Join.BEVEL);//直线      ,Path  path2 =, new 路径();   ,path2.moveTo (100,, 200);   ,path2.lineTo (300,, 200);   ,canvas.drawPath (path2, mPaint);      ,mPaint.reset();//重置   ,mPaint.setColor (Color.GREEN);   ,mPaint.setStyle (Paint.Style.FILL_AND_STROKE);   ,mPaint.setStrokeWidth (50);   ,mPaint.setStrokeCap (Paint.Cap.BUTT);//没有   ,mPaint.setStrokeJoin (Paint.Join.BEVEL);//直线      ,Path  path3 =, new 路径();   ,path3.moveTo (100,, 300);   ,path3.lineTo (300,, 300);   ,canvas.drawPath (path3, mPaint);      以前,}

怎么在Android中使用油漆进行绘图