Android Paint源码分析

 

今天学习下Paint这个类,决定从看源码开始学习。

先看类的定义就很有特点:public class Paint extends _Original_Paint ,后面这个_Original_Paint 是怎么个回事,希望大家解释,我不懂。

用到了Style,这个是一个内部的枚举类,有3种:FILL  (0),  STROKE (1),  FILL_AND_STROKE (2);

 /**
     * The Style specifies if the primitive being drawn is filled,
     * stroked, or both (in the same color). The default is FILL.
     */
    public enum Style

还有Align,仍然是一个内部枚举类,还是有3个值:LEFT    (0), CENTER  (1), RIGHT   (2);

 /**
     * Align specifies how drawText aligns its text relative to the
     * [x,y] coordinates. The default is LEFT.
     */
    public enum Align

有个Join,待解。。。

 /**
     * The Join specifies the treatment where lines and curve segments
     * join on a stroked path. The default is MITER.
     */
    public enum Join

还有个Cap,这个不知道干嘛用的,待查。。。

 /**
     * The Cap specifies the treatment for the beginning and ending of
     * stroked lines and paths. The default is BUTT.
     */
    public enum Cap

 

内部静态类:看代码可知,Paint和这个FontInfo关系很大

 public static final class FontInfo {
        Font mFont;
        java.awt.FontMetrics mMetrics;
    }

 

构造函数有三种:

public Paint() {
        this(0);
    }

    public Paint(int flags) {
        setFlags(flags | DEFAULT_PAINT_FLAGS);
        initFont();
    }

    public Paint(Paint paint) {
        set(paint);
        initFont();
    }

 

 

后面内容中用到了Typeface,个人认为就是一个字体样式的类,看它的源码,里面的内容比较简单。

 

看了看后面的方法,基本都是一些基本的方法,对字体颜色、大小、边距的设置等等。

 

Android 中的画笔是 Paint类,Paint 中包含了很多方法对其属性进行设置,主要方法如下:

setAntiAlias: 设置画笔的锯齿效果。
setColor: 设置画笔颜色
setARGB: 设置画笔的a,r,p,g值。
setAlpha: 设置Alpha值
setTextSize: 设置字体尺寸。
setStyle: 设置画笔风格,空心或者实心。
setStrokeWidth: 设置空心的边框宽度。
getColor: 得到画笔的颜色
getAlpha: 得到画笔的Alpha值。

Paint类介绍

*

* Paint即画笔,在绘图过程中起到了极其重要的作用,画笔主要保存了颜色,

* 样式等绘制信息,指定了如何绘制文本和图形,画笔对象有很多设置方法,

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值