saveLayerAlpha简单入门

package com.loaderman.customviewdemo;

import android.content.Context;
import android.graphics.*;
import android.util.AttributeSet;
import android.view.View;


public class SaveLayerUseExample extends View {
    private Paint mPaint;
    private Bitmap mBitmap;

    public SaveLayerUseExample(Context context, AttributeSet attrs) {
        super(context, attrs);
        mPaint = new Paint();
        mPaint.setColor(Color.RED);
        mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dog);
        ;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawBitmap(mBitmap, 0, 0, mPaint);

        int layerID = canvas.saveLayerAlpha(0, 0, 200, 200, 255, Canvas.ALL_SAVE_FLAG);
        canvas.drawColor(Color.WHITE);
        canvas.restoreToCount(layerID);
    }
}

效果:

posted on 2019-01-04 13:50  LoaderMan  阅读(542)  评论(0编辑  收藏  举报

导航