android Paint 简单使用

工作上不忙,于是在学习一下知识点 以作储备

今天学习了一下 paint的用法不多说上api

ARGB解释

//        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);
圆环渲染

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值