Java 类android.graphics.PorterDuff.Mode 实例源码

项目:boohee_v5.6    文件:BitmapHelper.java   
public static Bitmap roundBitmap(Bitmap bitmap, int i, int i2, float f, float f2, float f3,
                                 float f4) throws Throwable {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Rect rect = new Rect(0, 0, width, height);
    Bitmap createBitmap = (width == i && height == i2) ? Bitmap.createBitmap(bitmap.getWidth
            (), bitmap.getHeight(), Config.ARGB_8888) : Bitmap.createBitmap(i, i2, Config
            .ARGB_8888);
    Canvas canvas = new Canvas(createBitmap);
    Paint paint = new Paint();
    Rect rect2 = new Rect(0, 0, i, i2);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(-12434878);
    float[] fArr = new float[]{f, f, f2, f2, f3, f3, f4, f4};
    ShapeDrawable shapeDrawable = new ShapeDrawable(new RoundRectShape(fArr, new RectF(0.0f,
            0.0f, 0.0f, 0.0f), fArr));
    shapeDrawable.setBounds(rect2);
    shapeDrawable.draw(canvas);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect2, paint);
    return createBitmap;
}
项目:GitHub    文件:ImageLoaderUtil.java   
/**将图片改为圆角类型
 * @param bitmap
 * @param pixels
 * @return
 */
public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}
项目:GitHub    文件:ImageLoaderUtil.java   
/**将图片改为圆角类型
 * @param bitmap
 * @param pixels
 * @return
 */
public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}
项目:ticket-view    文件:TicketView.java   
private void init(AttributeSet attrs) {
    eraser.setXfermode(new PorterDuffXfermode(Mode.CLEAR));

    dashPaint.setARGB(255, 200, 200, 200);
    dashPaint.setStyle(Style.STROKE);
    dashPaint.setStrokeWidth(4);
    dashPaint.setPathEffect(new DashPathEffect(new float[] { 4, 8 }, 0));

    borderPaint.setARGB(255, 200, 200, 200);
    borderPaint.setStyle(Style.STROKE);
    borderPaint.setStrokeWidth(4);

    setLayerType(LAYER_TYPE_HARDWARE, null);

    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.TicketView);
    try {
        orientation = a.getInt(R.styleable.TicketView_tv_orientation, Orientation.VERTICAL);
        holeRadius = a.getFloat(R.styleable.TicketView_tv_holeRadius, DEFAULT_RADIUS);
        anchorViewId = a.getResourceId(R.styleable.TicketView_tv_anchor, NO_VALUE);
    } finally {
        a.recycle();
    }
}
项目:Mvp-Retrofit-Rxjava-Rxbus    文件:BitmapUtils.java   
/**
 * 图片圆角
 * 
 * @param bitmap
 * @param pixels
 * @return
 */
public static Bitmap getRoundBitmap(Bitmap bitmap, int pixels) {
    if (bitmap == null) {
        return null;
    }

    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xffffffff;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}
项目:boohee_v5.6    文件:DrawableWrapperDonut.java   
private boolean updateTint(int[] state) {
    if (!isCompatTintEnabled()) {
        return false;
    }
    ColorStateList tintList = this.mState.mTint;
    Mode tintMode = this.mState.mTintMode;
    if (tintList == null || tintMode == null) {
        this.mColorFilterSet = false;
        clearColorFilter();
        return false;
    }
    int color = tintList.getColorForState(state, tintList.getDefaultColor());
    if (this.mColorFilterSet && color == this.mCurrentColor && tintMode == this.mCurrentMode) {
        return false;
    }
    setColorFilter(color, tintMode);
    this.mCurrentColor = color;
    this.mCurrentMode = tintMode;
    this.mColorFilterSet = true;
    return true;
}
项目:PeSanKita-android    文件:TransportOptionsAdapter.java   
@Override
public View getView(int position, View convertView, ViewGroup parent) {
  if (convertView == null) {
    convertView = inflater.inflate(R.layout.transport_selection_list_item, parent, false);
  }

  TransportOption transport   = (TransportOption) getItem(position);
  ImageView       imageView   = ViewUtil.findById(convertView, R.id.icon);
  TextView        textView    = ViewUtil.findById(convertView, R.id.text);
  TextView        subtextView = ViewUtil.findById(convertView, R.id.subtext);

  imageView.getBackground().setColorFilter(transport.getBackgroundColor(), Mode.MULTIPLY);
  imageView.setImageResource(transport.getDrawable());
  textView.setText(transport.getDescription());

  if (transport.getSimName().isPresent()) {
    subtextView.setText(transport.getSimName().get());
    subtextView.setVisibility(View.VISIBLE);
  } else {
    subtextView.setVisibility(View.GONE);
  }

  return convertView;
}
项目:XERUNG    文件:ButtonFloat.java   
public Bitmap cropCircle(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
            bitmap.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}
项目:XERUNG    文件:LayoutRipple.java   
/**
 * @param bitmap
 * @return 设置涟漪的边界,涟漪在这个区域里面可见。这里可以设置四角的弧度数
 */
public Bitmap cropRoundRect(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
    bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    RectF rectF = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
    canvas.drawRoundRect(rectF, rippleBorderRadius, rippleBorderRadius, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}
项目:TakePhoto    文件:FileUtil.java   
/**
 * 将图片变为圆角
 * @param bitmap 原Bitmap图片
 * @param pixels 图片圆角的弧度(单位:像素(px))
 * @return 带有圆角的图片(Bitmap 类型)
 */
public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}
项目:XERUNG    文件:LayoutRipple.java   
/**
 * @param bitmap
 * @return 设置涟漪的边界,涟漪在这个区域里面可见。这里可以设置四角的弧度数
 */
public Bitmap cropRoundRect(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
    bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    RectF rectF = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
    canvas.drawRoundRect(rectF, rippleBorderRadius, rippleBorderRadius, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}
项目:APIJSON-Android-RxJava    文件:ImageLoaderUtil.java   
/**将图片改为圆角类型
 * @param bitmap
 * @param pixels
 * @return
 */
public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}
项目:AppCommonFrame    文件:BitmapUtil.java   
/**
 * 获得圆角图片 . <br>
 * @author liulongzhenhai 2012-8-1 下午5:24:57 <br>
 * @param bitmap 图片
 * @param roundPx 圆角度
 * @return 图片
 */
public static Bitmap getRoundedCornerBitmap(final Bitmap bitmap, final float roundPx) {
    final int w = bitmap.getWidth();
    final int h = bitmap.getHeight();
    final Bitmap output = Bitmap.createBitmap(w, h, Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, w, h);
    final RectF rectF = new RectF(rect);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}
项目:BBSSDK-for-Android    文件:ImageHelper.java   
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
    if (bitmap == null) {
        return null;
    }
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
            .getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}
项目:sealtalk-android-master    文件:BitmapUtils.java   
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
                                        bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = 12;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    if (null != bitmap) {
        bitmap.recycle();
        bitmap = null;
    }

    return output;
}
项目:XFrame    文件:XBitmapUtils.java   
/**
 * 合并
 *
 * @param bgd 后景Bitmap
 * @param fg  前景Bitmap
 * @return 合成后Bitmap
 */
public static Bitmap combineImagesToSameSize(Bitmap bgd, Bitmap fg) {
    Bitmap bmp;

    int width = bgd.getWidth() < fg.getWidth() ? bgd.getWidth() : fg
            .getWidth();
    int height = bgd.getHeight() < fg.getHeight() ? bgd.getHeight() : fg
            .getHeight();

    if (fg.getWidth() != width && fg.getHeight() != height) {
        fg = zoom(fg, width, height);
    }
    if (bgd.getWidth() != width && bgd.getHeight() != height) {
        bgd = zoom(bgd, width, height);
    }

    bmp = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Paint paint = new Paint();
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_ATOP));

    Canvas canvas = new Canvas(bmp);
    canvas.drawBitmap(bgd, 0, 0, null);
    canvas.drawBitmap(fg, 0, 0, paint);

    return bmp;
}
项目:GCSApp    文件:BitmapUtil.java   
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {
        System.gc();
        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(),
                Config.RGB_565);
//      Config.ARGB_8888);
        Canvas canvas = new Canvas(output);

        final int color = 0xff424242;
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        final RectF rectF = new RectF(rect);

        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);
        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);
        System.gc();
        return output;
    }
项目:boohee_v5.6    文件:SlidingPaneLayout.java   
private void dimChildView(View v, float mag, int fadeColor) {
    LayoutParams lp = (LayoutParams) v.getLayoutParams();
    if (mag > 0.0f && fadeColor != 0) {
        int color = (((int) (((float) ((-16777216 & fadeColor) >>> 24)) * mag)) << 24) | (ViewCompat.MEASURED_SIZE_MASK & fadeColor);
        if (lp.dimPaint == null) {
            lp.dimPaint = new Paint();
        }
        lp.dimPaint.setColorFilter(new PorterDuffColorFilter(color, Mode.SRC_OVER));
        if (ViewCompat.getLayerType(v) != 2) {
            ViewCompat.setLayerType(v, 2, lp.dimPaint);
        }
        invalidateChildRegion(v);
    } else if (ViewCompat.getLayerType(v) != 0) {
        if (lp.dimPaint != null) {
            lp.dimPaint.setColorFilter(null);
        }
        DisableLayerRunnable dlr = new DisableLayerRunnable(v);
        this.mPostedRunnables.add(dlr);
        ViewCompat.postOnAnimation(this, dlr);
    }
}
项目:letv    文件:SlidingPaneLayout.java   
private void dimChildView(View v, float mag, int fadeColor) {
    LayoutParams lp = (LayoutParams) v.getLayoutParams();
    if (mag > 0.0f && fadeColor != 0) {
        int color = (((int) (((float) ((-16777216 & fadeColor) >>> 24)) * mag)) << 24) | (ViewCompat.MEASURED_SIZE_MASK & fadeColor);
        if (lp.dimPaint == null) {
            lp.dimPaint = new Paint();
        }
        lp.dimPaint.setColorFilter(new PorterDuffColorFilter(color, Mode.SRC_OVER));
        if (ViewCompat.getLayerType(v) != 2) {
            ViewCompat.setLayerType(v, 2, lp.dimPaint);
        }
        invalidateChildRegion(v);
    } else if (ViewCompat.getLayerType(v) != 0) {
        if (lp.dimPaint != null) {
            lp.dimPaint.setColorFilter(null);
        }
        DisableLayerRunnable dlr = new DisableLayerRunnable(v);
        this.mPostedRunnables.add(dlr);
        ViewCompat.postOnAnimation(this, dlr);
    }
}
项目:HutHelper    文件:DragLayout.java   
private void animateView(float percent) {
    float f1 = 1 - percent * 0.3f;
    ViewHelper.setScaleX(vg_main, f1);   //主布局逐渐变大
    ViewHelper.setScaleY(vg_main, f1);
    ViewHelper.setTranslationX(vg_left, -vg_left.getWidth() / 2.3f
            + vg_left.getWidth() / 2.3f * percent);
    ViewHelper.setScaleX(vg_left, 0.5f + 0.5f * percent);//左边的布局逐渐变小
    ViewHelper.setScaleY(vg_left, 0.5f + 0.5f * percent);
    ViewHelper.setAlpha(vg_left, percent);
    if (isShowShadow) {
        ViewHelper.setScaleX(iv_shadow, f1 * 1.4f * (1 - percent * 0.12f));
        ViewHelper.setScaleY(iv_shadow, f1 * 1.85f * (1 - percent * 0.12f));
    }
    getBackground().setColorFilter(
            evaluate(percent, Color.BLACK, Color.TRANSPARENT),
            Mode.SRC_OVER);
}
项目:boohee_v5.6    文件:VectorDrawableCompat.java   
private static Mode parseTintModeCompat(int value, Mode defaultMode) {
    switch (value) {
        case 3:
            return Mode.SRC_OVER;
        case 5:
            return Mode.SRC_IN;
        case 9:
            return Mode.SRC_ATOP;
        case 14:
            return Mode.MULTIPLY;
        case 15:
            return Mode.SCREEN;
        case 16:
            return Mode.ADD;
        default:
            return defaultMode;
    }
}
项目:boohee_v5.6    文件:SocialResHelper.java   
private static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap createBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config
            .ARGB_8888);
    Canvas canvas = new Canvas(createBitmap);
    Paint paint = new Paint();
    Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    RectF rectF = new RectF(rect);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(-12434878);
    if (RESUTIL_V2_DUBUG) {
        canvas.drawRoundRect(rectF, (float) (bitmap.getWidth() / 2), (float) (bitmap
                .getHeight() / 2), paint);
    } else {
        canvas.drawRoundRect(rectF, (float) (bitmap.getWidth() / 6), (float) (bitmap
                .getHeight() / 6), paint);
    }
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    bitmap.recycle();
    return createBitmap;
}
项目:FreeStreams-TVLauncher    文件:ImageTools.java   
/**
 *圆角图片
 * @param bitmap
 * @return
 */
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = 12;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;

}
项目:Cable-Android    文件:TransportOptionsAdapter.java   
@Override
public View getView(int position, View convertView, ViewGroup parent) {
  if (convertView == null) {
    convertView = inflater.inflate(R.layout.transport_selection_list_item, parent, false);
  }

  TransportOption transport   = (TransportOption) getItem(position);
  ImageView       imageView   = ViewUtil.findById(convertView, R.id.icon);
  TextView        textView    = ViewUtil.findById(convertView, R.id.text);
  TextView        subtextView = ViewUtil.findById(convertView, R.id.subtext);

  imageView.getBackground().setColorFilter(transport.getBackgroundColor(), Mode.MULTIPLY);
  imageView.setImageResource(transport.getDrawable());
  textView.setText(transport.getDescription());

  if (transport.getSimName().isPresent()) {
    subtextView.setText(transport.getSimName().get());
    subtextView.setVisibility(View.VISIBLE);
  } else {
    subtextView.setVisibility(View.GONE);
  }

  return convertView;
}
项目:RabbitCloud    文件:RoundRectImageView.java   
/**
 * 获取圆角矩形图片方法
 */
private Bitmap getRoundBitmap(Bitmap bitmap, int roundPx) {  
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),  
            bitmap.getHeight(), Config.ARGB_8888);  
    Canvas canvas = new Canvas(output);  

    final int color = 0xff424242;

    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());  
    final RectF rectF = new RectF(rect);
    paint.setAntiAlias(true);  
    canvas.drawARGB(0, 0, 0, 0);  
    paint.setColor(color);  
    int x = bitmap.getWidth(); 

    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));  
    canvas.drawBitmap(bitmap, rect, rect, paint);  
    return output;  


}
项目:boohee_v5.6    文件:UCropActivity.java   
private void setupAppBar() {
    setStatusBarColor(this.mStatusBarColor);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setBackgroundColor(this.mToolbarColor);
    toolbar.setTitleTextColor(this.mToolbarTextColor);
    TextView toolbarTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
    toolbarTitle.setTextColor(this.mToolbarTextColor);
    toolbarTitle.setText(this.mToolbarTitle);
    Drawable stateButtonDrawable = ContextCompat.getDrawable(this, R.drawable.ucrop_ic_cross)
            .mutate();
    stateButtonDrawable.setColorFilter(this.mToolbarTextColor, Mode.SRC_ATOP);
    toolbar.setNavigationIcon(stateButtonDrawable);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(false);
    }
}
项目:boohee_v5.6    文件:VectorDrawableCompat.java   
public void setTintMode(Mode tintMode) {
    if (this.mDelegateDrawable != null) {
        DrawableCompat.setTintMode(this.mDelegateDrawable, tintMode);
        return;
    }
    VectorDrawableCompatState state = this.mVectorState;
    if (state.mTintMode != tintMode) {
        state.mTintMode = tintMode;
        this.mTintFilter = updateTintFilter(this.mTintFilter, state.mTint, tintMode);
        invalidateSelf();
    }
}
项目:q-mail    文件:AlternateRecipientAdapter.java   
private void setCryptoStatusView(RecipientTokenHolder holder, @DrawableRes int cryptoStatusRes,
        @AttrRes int cryptoStatusColorAttr) {
    Resources resources = context.getResources();

    Drawable drawable = resources.getDrawable(cryptoStatusRes);
    // noinspection ConstantConditions, we know the resource exists!
    drawable.mutate();

    int cryptoStatusColor = ThemeUtils.getStyledColor(context, cryptoStatusColorAttr);
    drawable.setColorFilter(cryptoStatusColor, Mode.SRC_ATOP);

    holder.itemCryptoStatusIcon.setImageDrawable(drawable);
    holder.itemCryptoStatus.setVisibility(View.VISIBLE);
}
项目:GitHub    文件:LineChartRenderer.java   
@Override
public void draw(Canvas canvas) {
    final LineChartData data = dataProvider.getLineChartData();

    final Canvas drawCanvas;

    // softwareBitmap can be null if chart is rendered in layout editor. In that case use default canvas and not
    // softwareCanvas.
    if (null != softwareBitmap) {
        drawCanvas = softwareCanvas;
        drawCanvas.drawColor(Color.TRANSPARENT, Mode.CLEAR);
    } else {
        drawCanvas = canvas;
    }

    for (Line line : data.getLines()) {
        if (line.hasLines()) {
            if (line.isCubic()) {
                drawSmoothPath(drawCanvas, line);
            } else if (line.isSquare()) {
                drawSquarePath(drawCanvas, line);
            } else {
                drawPath(drawCanvas, line);
            }
        }
    }

    if (null != softwareBitmap) {
        canvas.drawBitmap(softwareBitmap, 0, 0, null);
    }
}
项目:phonk    文件:TouchAreaView.java   
@Override
protected void onDraw(Canvas canvas) {

    synchronized (this) {

        // saved
        canvas.drawBitmap(bitmap, new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()),
                new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()), null);

        // paint
        // mPaint.setStyle(Styler.STROKE);

        if (showArea) {
            mPaint.setColor(0x88FFFFFF);
            mPaint.setStyle(Style.STROKE);

            mCanvas.drawRect(new RectF(0, 0, mWidth, mHeight), mPaint);

            if (touching) {
                mPaint.setStyle(Paint.Style.FILL);
                mPaint.setColor(0x880000FF);
                mCanvas.drawRect(new RectF(0, 0, mWidth, mHeight), mPaint);
            } else {
                mPaint.setStyle(Paint.Style.STROKE);
                mCanvas.drawColor(0, Mode.CLEAR);
                mPaint.setColor(0x88000000);
                mCanvas.drawRect(new RectF(0, 0, mWidth, mHeight), mPaint);
            }
        }
    }
}
项目:AppCommonFrame    文件:BitmapUtil.java   
/**
 * 获得带倒影的图片 . <br>
 * @author liulongzhenhai 2012-8-1 下午5:25:37 <br>
 * @param bitmap 图片对象
 * @return 图片
 */
public static Bitmap createReflectionImageWithOrigin(final Bitmap bitmap) {
    final int reflectionGap = 4;
    final int w = bitmap.getWidth();
    final int h = bitmap.getHeight();

    final Matrix matrix = new Matrix();
    matrix.preScale(1, -1);

    final Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, h / 2, w, h / 2, matrix, false);

    final Bitmap bitmapWithReflection = Bitmap.createBitmap(w, h + h / 2, Config.ARGB_8888);

    final Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(bitmap, 0, 0, null);
    final Paint deafalutPaint = new Paint();
    canvas.drawRect(0, h, w, h + reflectionGap, deafalutPaint);

    canvas.drawBitmap(reflectionImage, 0, h + reflectionGap, null);

    final Paint paint = new Paint();
    final LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight()
            + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
    paint.setShader(shader);
    // Set the Transfer mode to be porter duff and destination in
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    // Draw a rectangle using the paint with our linear gradient
    canvas.drawRect(0, h, w, bitmapWithReflection.getHeight() + reflectionGap, paint);

    return bitmapWithReflection;
}
项目:XFrame    文件:XBitmapUtils.java   
/**
 * 获得带倒影的Bitmap
 *
 * @param bitmap 源Bitmap
 * @return 带倒影的Bitmap
 */
public static Bitmap createReflectionBitmap(Bitmap bitmap) {
    final int reflectionGap = 4;
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);

    Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2,
            width, height / 2, matrix, false);

    Bitmap bitmapWithReflection = Bitmap.createBitmap(width,
            (height + height / 2), Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(bitmap, 0, 0, null);
    Paint deafalutPaint = new Paint();
    canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint);

    canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);

    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,
            bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff,
            0x00ffffff, TileMode.CLAMP);
    paint.setShader(shader);
    // Set the Transfer mode to be porter duff and destination in
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    // Draw a rectangle using the paint with our linear gradient
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()
            + reflectionGap, paint);

    return bitmapWithReflection;
}
项目:letv    文件:RoundedVignetteBitmapDisplayer.java   
protected void onBoundsChange(Rect bounds) {
    super.onBoundsChange(bounds);
    RadialGradient vignette = new RadialGradient(this.mRect.centerX(), (this.mRect.centerY() * 1.0f) / 0.7f, this.mRect.centerX() * 1.3f, new int[]{0, 0, 2130706432}, new float[]{0.0f, 0.7f, 1.0f}, TileMode.CLAMP);
    Matrix oval = new Matrix();
    oval.setScale(1.0f, 0.7f);
    vignette.setLocalMatrix(oval);
    this.paint.setShader(new ComposeShader(this.bitmapShader, vignette, Mode.SRC_OVER));
}
项目:letv    文件:CommentHeadImageViewPlayerLibs.java   
public Bitmap getCircleBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getWidth(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(-12434878);
    int radius = bitmap.getWidth() >> 1;
    canvas.drawCircle((float) radius, (float) radius, (float) radius, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}
项目:GravityBox    文件:PieItem.java   
public void setColor(PieController.ColorInfo colorInfo) {
    mBackgroundPaint.setColor(colorInfo.bgColor);
    mSelectedPaint.setColor(colorInfo.selectedColor);
    mOutlinePaint.setColor(colorInfo.outlineColor);

    if (mView instanceof ImageView) {
        ImageView imageView = (ImageView)mView;
        Drawable drawable = imageView.getDrawable();
        if (drawable != null) {
            drawable.setColorFilter(colorInfo.fgColor, Mode.SRC_ATOP);
            imageView.setImageDrawable(drawable);
        }
    }
}
项目:boohee_v5.6    文件:DrawableWrapperLollipop.java   
public void setTintMode(Mode tintMode) {
    if (isCompatTintEnabled()) {
        setCompatTintMode(tintMode);
    } else {
        this.mDrawable.setTintMode(tintMode);
    }
}
项目:boohee_v5.6    文件:AppCompatDrawableManager.java   
private static boolean tintDrawableUsingColorFilter(@NonNull Context context, @DrawableRes int resId, @NonNull Drawable drawable) {
    Mode tintMode = DEFAULT_MODE;
    boolean colorAttrSet = false;
    int colorAttr = 0;
    int alpha = -1;
    if (arrayContains(COLORFILTER_TINT_COLOR_CONTROL_NORMAL, resId)) {
        colorAttr = R.attr.colorControlNormal;
        colorAttrSet = true;
    } else if (arrayContains(COLORFILTER_COLOR_CONTROL_ACTIVATED, resId)) {
        colorAttr = R.attr.colorControlActivated;
        colorAttrSet = true;
    } else if (arrayContains(COLORFILTER_COLOR_BACKGROUND_MULTIPLY, resId)) {
        colorAttr = 16842801;
        colorAttrSet = true;
        tintMode = Mode.MULTIPLY;
    } else if (resId == R.drawable.abc_list_divider_mtrl_alpha) {
        colorAttr = 16842800;
        colorAttrSet = true;
        alpha = Math.round(40.8f);
    }
    if (!colorAttrSet) {
        return false;
    }
    if (DrawableUtils.canSafelyMutateDrawable(drawable)) {
        drawable = drawable.mutate();
    }
    drawable.setColorFilter(getPorterDuffColorFilter(ThemeUtils.getThemeAttrColor(context, colorAttr), tintMode));
    if (alpha != -1) {
        drawable.setAlpha(alpha);
    }
    return true;
}
项目:eggs-android    文件:RoundedImageView.java   
private Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
    Bitmap finalBitmap;

    if (bitmap.getWidth() != radius || bitmap.getHeight() != radius) {
        finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius, false);
    } else {
        finalBitmap = bitmap;
    }

    Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),
            finalBitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
            finalBitmap.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(finalBitmap.getWidth() / 2,
            finalBitmap.getHeight() / 2,
            finalBitmap.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(finalBitmap, rect, rect, paint);

    return output;
}
项目:boohee_v5.6    文件:VectorDrawableCompat.java   
private void updateStateFromTypedArray(TypedArray a, XmlPullParser parser) throws XmlPullParserException {
    VectorDrawableCompatState state = this.mVectorState;
    VPathRenderer pathRenderer = state.mVPathRenderer;
    state.mTintMode = parseTintModeCompat(TypedArrayUtils.getNamedInt(a, parser, "tintMode", 6, -1), Mode.SRC_IN);
    ColorStateList tint = a.getColorStateList(1);
    if (tint != null) {
        state.mTint = tint;
    }
    state.mAutoMirrored = TypedArrayUtils.getNamedBoolean(a, parser, "autoMirrored", 5, state.mAutoMirrored);
    pathRenderer.mViewportWidth = TypedArrayUtils.getNamedFloat(a, parser, "viewportWidth", 7, pathRenderer.mViewportWidth);
    pathRenderer.mViewportHeight = TypedArrayUtils.getNamedFloat(a, parser, "viewportHeight", 8, pathRenderer.mViewportHeight);
    if (pathRenderer.mViewportWidth <= 0.0f) {
        throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires viewportWidth > 0");
    } else if (pathRenderer.mViewportHeight <= 0.0f) {
        throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires viewportHeight > 0");
    } else {
        pathRenderer.mBaseWidth = a.getDimension(3, pathRenderer.mBaseWidth);
        pathRenderer.mBaseHeight = a.getDimension(2, pathRenderer.mBaseHeight);
        if (pathRenderer.mBaseWidth <= 0.0f) {
            throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires width > 0");
        } else if (pathRenderer.mBaseHeight <= 0.0f) {
            throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires height > 0");
        } else {
            pathRenderer.setAlpha(TypedArrayUtils.getNamedFloat(a, parser, "alpha", 4, pathRenderer.getAlpha()));
            String name = a.getString(0);
            if (name != null) {
                pathRenderer.mRootName = name;
                pathRenderer.mVGTargetsMap.put(name, pathRenderer);
            }
        }
    }
}
项目:amap    文件:MIP_BitmapUtils.java   
/**
 * 图片创建倒影 TODO(这里用一句话描述这个方法的作用)
 * 
 * @author 2013-10-12 下午3:58:39
 * @param originalImage
 * @param number
 * @return Bitmap
 */
public static Bitmap createReflectedImage(Bitmap originalImage, int number)
{
    final int reflectionGap = 0; // 倒影和原图片间的距离
    int width = originalImage.getWidth();
    int height = originalImage.getHeight();

    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);

    double reflectHeight = number / 100.00;

    number = (int)(height * reflectHeight);
    // 倒影部分
    Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, number, width, number, matrix, false);
    // 要返回的倒影图片
    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + number), Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmapWithReflection);
    // 画原来的图片
    canvas.drawBitmap(originalImage, 0, 0, null);

    // Paint defaultPaint = new Paint();
    // //倒影和原图片间的距离
    // canvas.drawRect(0, height, width, height + reflectionGap,
    // defaultPaint);
    // 画倒影部分
    canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);

    Paint paint = new Paint();
    LinearGradient shader =
        new LinearGradient(0, originalImage.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap,
            0x70ffffff, 0x00ffffff, TileMode.MIRROR);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);
    return bitmapWithReflection;
}