2

我正在尝试使用 PorterDuff.Mode.DST_IN 使用CircularProgressView屏蔽图像视图,这是用于屏蔽的示例代码

 public static Bitmap getMaskedBitmap(Resources res,  int sourceResId,Bitmap mask) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        options.inMutable = true;
    }
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    Bitmap source = BitmapFactory.decodeResource(res, sourceResId, options);
    Bitmap bitmap;
    if (source.isMutable()) {
        bitmap = source;
    } else {
        bitmap = source.copy(Bitmap.Config.ARGB_8888, true);
        source.recycle();
    }
    bitmap.setHasAlpha(true);
    Canvas canvas = new Canvas(bitmap);

    Paint paint = new Paint();
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    canvas.drawBitmap(mask, 0, 0, paint);

    mask.recycle();
    return bitmap;
}

源图像 = 将是来自可绘制对象的透明字母“C”,例如这个在此处输入图像描述

并且掩码图像应该来自 CircularProgressView。我想使用 CircularProgressView 以掩盖字母 C 的点(比例为 1/10)为基础,用纯白色填充透明字母“C”。这可能吗?

4

0 回答 0