工作上不忙,于是在学习一下知识点 以作储备
今天学习了一下 paint的用法不多说上api
// mPaint.setColor(Color.RED);//设置画笔颜色
// mPaint.setARGB(255, 138, 43, 226); // 设置 Paint对象颜色 0-255 参数1 透明度 255完全不透明
mPaint.setAntiAlias(true);//是否抗锯齿
// mPaint.setAlpha(127);//设置透明度
mPaint.setStyle(Paint.Style.FILL);//FILL设置只绘制图形内容 STROKE设置只绘制图形的边 FILL_AND_STROKE设置都绘制
// mPaint.setStrokeWidth(4);//设置描边宽度
// mPaint.setStrokeCap(Paint.Cap.ROUND);//圆角效果
// mPaint.setStrokeJoin(Paint.Join.BEVEL);//拐角风格
// mPaint.setShader(new SweepGradient(250, 250, Color.BLUE, Color.RED)); //设置环形渲染器
// mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DARKEN)); //设置图层混合模式
// mPaint.setColorFilter(new LightingColorFilter(0x00ffff, 0x000000)); //设置颜色过滤器
// mPaint.setFilterBitmap(true); //设置双线性过滤
// mPaint.setMaskFilter(new BlurMaskFilter(10, BlurMaskFilter.Blur.NORMAL));//设置画笔遮罩滤镜 ,传入度数和样式
// mPaint.setTextScaleX(2);// 设置文本缩放倍数
// mPaint.setTextSize(38);// 设置字体大小
// mPaint.setTextAlign(Paint.Align.LEFT);//对其方式
// mPaint.setUnderlineText(true);// 设置下划线
//
// String str = "Android小菜鸡";
// Rect rect = new Rect();
// mPaint.getTextBounds(str, 0, str.length(), rect); //测量文本大小,将文本大小信息存放在rect中
// mPaint.measureText(str); //获取文本的宽
// mPaint.getFontMetrics(); //获取字体度量对象
这些都是paint的一些基本使用 点进去paint类去看源码 发现里面会有好多 native方法,直接调用底层去操作的。
说一下新学习的几个api
Shader各个用法
线性渲染
上个图
上代码
/**
* 1.线性渲染,LinearGradient(float x0, float y0, float x1, float y1, @NonNull @ColorInt int colors[], @Nullable float positions[], @NonNull TileMode tile)
* (x0,y0):渐变起始点坐标
* (x1,y1):渐变结束点坐标
* color0:渐变开始点颜色,16进制的颜色表示,必须要带有透明度
* color1:渐变结束颜色
* colors:渐变数组
* positions:位置数组,position的取值范围[0,1],作用是指定某个位置的颜色值,如果传null,渐变就线性变化。
* tile:用于指定控件区域大于指定的渐变区域时,空白区域的颜色填充方法
*/
// mShader = new LinearGradient(0, 0, 500, 500, new int[]{Color.RED, Color.BLUE, Color.WHITE}, new float[]{0.f, 0.5f, 1}, Shader.TileMode.REPEAT);
圆环渲染