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); } }
效果:
最后,关注【码上加油站】微信公众号后,有疑惑有问题想加油的小伙伴可以码上加入社群,让我们一起码上加油吧!!!