• PorterDuffXfermode之PorterDuff.Mode.LIGHTEN


    package com.loaderman.customviewdemo.view;
    
    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Canvas;
    import android.graphics.Paint;
    import android.graphics.PorterDuff;
    import android.graphics.PorterDuffXfermode;
    import android.util.AttributeSet;
    import android.view.View;
    
    import com.loaderman.customviewdemo.R;
    
    
    public class LightBookView extends View {
        private Paint mBitPaint;
        private Bitmap BmpDST,BmpSRC;
    
        public LightBookView(Context context, AttributeSet attrs) {
            super(context, attrs);
            mBitPaint = new Paint();
            BmpDST = BitmapFactory.decodeResource(getResources(), R.drawable.book_bg, null);
            BmpSRC = BitmapFactory.decodeResource(getResources(),R.drawable.book_light,null);
        }
    
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
    
            canvas.save();
    
            canvas.drawBitmap(BmpDST,0,0,mBitPaint);
            mBitPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.LIGHTEN));
            canvas.drawBitmap(BmpSRC,0,0,mBitPaint);
    
            mBitPaint.setXfermode(null);
            canvas.restore();
        }
    }
      <com.loaderman.customviewdemo.view.LightBookView
          android:layout_width="match_parent"
          android:layout_height="match_parent" />

    效果图:

  • 相关阅读:
    联考20200604 T2 宝石
    联考20200604 T1 旅游
    联考20200603 T2 排列
    [HAOI2017]八纵八横
    联考20200603 T1 解码
    [POI2011]KON-Conspiracy
    CF917D Stranger Trees
    CF1278F Cards
    CF809E Surprise me!
    NOI2016 循环之美
  • 原文地址:https://www.cnblogs.com/loaderman/p/10215098.html
Copyright © 2020-2023  润新知