saveLayerAlpha()当调用这个函数的时候 ,之前程序中的 平移 旋转 缩放的操作都会得到保存! calls to translate, scale, rotate, skew, concat or clipRect, clipPath all operate on this copy. When the balancing call to restore() is made, this copy is deleted and the previous matrix/clip state is restored. saveLayerAlpha()之后的这些操作,当调用restore()之后,这些操作都不会被保存,canvas会恢复到saveLayerAlpha()Zhi前的状态。
还有一点要特别注意的是 saveLayerAlpha()和resotre()要同时使用,才能够在canvas 画出多个层次,就是花多少层就要有多少对两个函数!
private static class SampleView extends View {
private static final int LAYER_FLAGS = Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG
| Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG
| Canvas.CLIP_TO_LAYER_SAVE_FLAG;
private Paint mPaint;
public SampleView(Context context) {
super(context);
setFocusable(true);
mPaint = new Paint();
mPaint.