java类android.graphics.PorterDuffColorFilter的实例源码

ConversationUpdateItem.java 文件源码 项目:Cable-Android 阅读 26 收藏 0 点赞 0 评论 0
private void setTimerRecord(final MessageRecord messageRecord) {
  if (messageRecord.getExpiresIn() > 0) {
    icon.setImageResource(R.drawable.ic_timer_white_24dp);
    icon.setColorFilter(new PorterDuffColorFilter(Color.parseColor("#757575"), PorterDuff.Mode.MULTIPLY));
  } else {
    icon.setImageResource(R.drawable.ic_timer_off_white_24dp);
    icon.setColorFilter(new PorterDuffColorFilter(Color.parseColor("#757575"), PorterDuff.Mode.MULTIPLY));
  }

  body.setText(messageRecord.getDisplayBody());
  date.setVisibility(View.GONE);
}
ImageUtils.java 文件源码 项目:GitHub 阅读 31 收藏 0 点赞 0 评论 0
/**
 * 快速模糊图片
 * <p>先缩小原图,对小图进行模糊,再放大回原先尺寸</p>
 *
 * @param src     源图片
 * @param scale   缩放比例(0...1)
 * @param radius  模糊半径(0...25)
 * @param recycle 是否回收
 * @return 模糊后的图片
 */
public static Bitmap fastBlur(final Bitmap src,
                              @FloatRange(from = 0, to = 1, fromInclusive = false) final float scale,
                              @FloatRange(from = 0, to = 25, fromInclusive = false) final float radius,
                              final boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    int width = src.getWidth();
    int height = src.getHeight();
    Matrix matrix = new Matrix();
    matrix.setScale(scale, scale);
    Bitmap scaleBitmap = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
    Canvas canvas = new Canvas();
    PorterDuffColorFilter filter = new PorterDuffColorFilter(
            Color.TRANSPARENT, PorterDuff.Mode.SRC_ATOP);
    paint.setColorFilter(filter);
    canvas.scale(scale, scale);
    canvas.drawBitmap(scaleBitmap, 0, 0, paint);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        scaleBitmap = renderScriptBlur(scaleBitmap, radius, recycle);
    } else {
        scaleBitmap = stackBlur(scaleBitmap, (int) radius, recycle);
    }
    if (scale == 1) return scaleBitmap;
    Bitmap ret = Bitmap.createScaledBitmap(scaleBitmap, width, height, true);
    if (scaleBitmap != null && !scaleBitmap.isRecycled()) scaleBitmap.recycle();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
ToastUtils.java 文件源码 项目:GitHub 阅读 34 收藏 0 点赞 0 评论 0
private static void setBgAndGravity() {
    View toastView = sToast.getView();
    if (bgResource != -1) {
        toastView.setBackgroundResource(bgResource);
    } else if (bgColor != COLOR_DEFAULT) {
        Drawable background = toastView.getBackground();
        background.setColorFilter(new PorterDuffColorFilter(bgColor, PorterDuff.Mode.SRC_IN));
    }
    sToast.setGravity(gravity, xOffset, yOffset);
}
ImageUtils.java 文件源码 项目:Android-UtilCode 阅读 30 收藏 0 点赞 0 评论 0
/**
 * 快速模糊图片
 * <p>先缩小原图,对小图进行模糊,再放大回原先尺寸</p>
 *
 * @param src     源图片
 * @param scale   缩放比例(0...1)
 * @param radius  模糊半径(0...25)
 * @param recycle 是否回收
 * @return 模糊后的图片
 */
public static Bitmap fastBlur(Bitmap src,
                              @FloatRange(from = 0, to = 1, fromInclusive = false) float scale,
                              @FloatRange(from = 0, to = 25, fromInclusive = false) float radius,
                              boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    int width = src.getWidth();
    int height = src.getHeight();
    int scaleWidth = (int) (width * scale + 0.5f);
    int scaleHeight = (int) (height * scale + 0.5f);
    if (scaleWidth == 0 || scaleHeight == 0) return null;
    Bitmap scaleBitmap = Bitmap.createScaledBitmap(src, scaleWidth, scaleHeight, true);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
    Canvas canvas = new Canvas();
    PorterDuffColorFilter filter = new PorterDuffColorFilter(
            Color.TRANSPARENT, PorterDuff.Mode.SRC_ATOP);
    paint.setColorFilter(filter);
    canvas.scale(scale, scale);
    canvas.drawBitmap(scaleBitmap, 0, 0, paint);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        scaleBitmap = renderScriptBlur(scaleBitmap, radius);
    } else {
        scaleBitmap = stackBlur(scaleBitmap, (int) radius, recycle);
    }
    if (scale == 1) return scaleBitmap;
    Bitmap ret = Bitmap.createScaledBitmap(scaleBitmap, width, height, true);
    if (scaleBitmap != null && !scaleBitmap.isRecycled()) scaleBitmap.recycle();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
ConversationUpdateItem.java 文件源码 项目:PeSanKita-android 阅读 23 收藏 0 点赞 0 评论 0
private void setTimerRecord(final MessageRecord messageRecord) {
  if (messageRecord.getExpiresIn() > 0) {
    icon.setImageResource(R.drawable.ic_timer_white_24dp);
    icon.setColorFilter(new PorterDuffColorFilter(Color.parseColor("#757575"), PorterDuff.Mode.MULTIPLY));
  } else {
    icon.setImageResource(R.drawable.ic_timer_off_white_24dp);
    icon.setColorFilter(new PorterDuffColorFilter(Color.parseColor("#757575"), PorterDuff.Mode.MULTIPLY));
  }

  body.setText(messageRecord.getDisplayBody());
  date.setVisibility(View.GONE);
}
AddPillSetTime.java 文件源码 项目:ePills 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Selects the Day on position 'index'.
 * @param index
 * @param dayLayout
 * @param check: True if checkDays() should be called.
 */
private void activateDay(int index, LinearLayout dayLayout, boolean check) {
    weekdaysSelection[index] = true;

    dayLayout.setTag(true);
    Drawable bg = ContextCompat.getDrawable(getBaseContext(), R.drawable.circle_step);
    int colorPrimary = ContextCompat.getColor(getBaseContext(), R.color.accent);
    bg.setColorFilter(new PorterDuffColorFilter(colorPrimary, PorterDuff.Mode.SRC_IN));
    dayLayout.setBackground(bg);
    TextView day = (TextView) dayLayout.findViewById(R.id.day);
    day.setTextColor(ContextCompat.getColor(getBaseContext(),R.color.md_white_1000));
    if(check) {
        checkDays();
    }
}
HourglassView.java 文件源码 项目:PeSanKita-android 阅读 25 收藏 0 点赞 0 评论 0
public HourglassView(Context context, AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);

  if (attrs != null) {
    TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HourglassView, 0, 0);
    this.empty = BitmapFactory.decodeResource(getResources(), typedArray.getResourceId(R.styleable.HourglassView_empty, 0));
    this.full  = BitmapFactory.decodeResource(getResources(), typedArray.getResourceId(R.styleable.HourglassView_full, 0));
    this.tint  = typedArray.getColor(R.styleable.HourglassView_tint, 0);
    this.percentage = typedArray.getInt(R.styleable.HourglassView_percentage, 50);
    this.offset = typedArray.getInt(R.styleable.HourglassView_offset, 0);
    typedArray.recycle();
  }

  this.backgroundPaint = new Paint();
  this.foregroundPaint = new Paint();
  this.progressPaint   = new Paint();

  this.backgroundPaint.setColorFilter(new PorterDuffColorFilter(tint, PorterDuff.Mode.MULTIPLY));
  this.foregroundPaint.setColorFilter(new PorterDuffColorFilter(tint, PorterDuff.Mode.MULTIPLY));

  this.progressPaint.setColor(getResources().getColor(R.color.black));
  this.progressPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

  if (android.os.Build.VERSION.SDK_INT >= 11)
  {
    setLayerType(View.LAYER_TYPE_SOFTWARE, null);
  }
}
BGAQRCodeUtil.java 文件源码 项目:Hitalk 阅读 24 收藏 0 点赞 0 评论 0
public static Bitmap makeTintBitmap(Bitmap inputBitmap, int tintColor) {
    if (inputBitmap == null) {
        return null;
    }

    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap.getWidth(), inputBitmap.getHeight(), inputBitmap.getConfig());
    Canvas canvas = new Canvas(outputBitmap);
    Paint paint = new Paint();
    paint.setColorFilter(new PorterDuffColorFilter(tintColor, PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(inputBitmap, 0, 0, paint);
    return outputBitmap;
}
QMUIRadiusImageView.java 文件源码 项目:qmui 阅读 32 收藏 0 点赞 0 评论 0
public void setSelectedMaskColor(@ColorInt int selectedMaskColor) {
    if (mSelectedMaskColor != selectedMaskColor) {
        mSelectedMaskColor = selectedMaskColor;
        if (mSelectedMaskColor != Color.TRANSPARENT) {
            mSelectedColorFilter = new PorterDuffColorFilter(mSelectedMaskColor, PorterDuff.Mode.DARKEN);
        } else {
            mSelectedColorFilter = null;
        }
        if (mIsSelected) {
            invalidate();
        }
    }
    mSelectedMaskColor = selectedMaskColor;
}
ImageUtils.java 文件源码 项目:MediaNotification 阅读 30 收藏 0 点赞 0 评论 0
public static Bitmap setBitmapColor(Bitmap bitmap, int color) {
    Bitmap result = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() - 1, bitmap.getHeight() - 1);
    Paint paint = new Paint();
    paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));

    Canvas canvas = new Canvas(result);
    canvas.drawBitmap(result, 0, 0, paint);

    return result;
}


问题


面经


文章

微信
公众号

扫码关注公众号