当前位置: 首页>>代码示例>>Java>>正文


Java PorterDuffXfermode类代码示例

本文整理汇总了Java中android.graphics.PorterDuffXfermode的典型用法代码示例。如果您正苦于以下问题:Java PorterDuffXfermode类的具体用法?Java PorterDuffXfermode怎么用?Java PorterDuffXfermode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PorterDuffXfermode类属于android.graphics包,在下文中一共展示了PorterDuffXfermode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRoundedCornerBitmap

import android.graphics.PorterDuffXfermode; //导入依赖的package包/类
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(outBitmap);
    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 = bitmap.getWidth() / 2;
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPX, roundPX, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return outBitmap;
}
 
开发者ID:xiaoxiaoqingyi,项目名称:mine-android-repository,代码行数:18,代码来源:BitmapUtils.java

示例2: getRCB

import android.graphics.PorterDuffXfermode; //导入依赖的package包/类
/**
 * 图片圆角处理
 *
 * @param bitmap
 * @param roundPX
 * @return
 */
public static Bitmap getRCB(Bitmap bitmap, float roundPX) {
    // RCB means
    // Rounded
    // Corner Bitmap
    Bitmap dstbmp = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(dstbmp);

    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(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return dstbmp;
}
 
开发者ID:xiaoxiaoqingyi,项目名称:mine-android-repository,代码行数:28,代码来源:BitmapUtils.java

示例3: getRoundBitmap

import android.graphics.PorterDuffXfermode; //导入依赖的package包/类
/**
 * 图片圆角处理
 *
 * @param bitmap
 * @param roundPX
 * @return
 */
public static Bitmap getRoundBitmap(Bitmap bitmap, float roundPX) {
    // RCB means
    // Rounded
    // Corner Bitmap
    Bitmap dstbmp = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas(dstbmp);

    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(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return dstbmp;
}
 
开发者ID:sundevin,项目名称:utilsLibrary,代码行数:28,代码来源:BitmapUtils.java

示例4: Gauge

import android.graphics.PorterDuffXfermode; //导入依赖的package包/类
public Gauge(final float startAngle, final float maxAngle, final Bitmap background, final Bitmap dynamic,
        final Bitmap foreground, final float x1, final float y1, final float x2, final float y2)
{
    this.startAngle = startAngle;
    this.maxAngle = maxAngle;
    this.background = background;
    this.dynamic = dynamic;
    this.foreground = foreground;
    width = background.getWidth();
    height = background.getHeight();
    drawBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    drawCanvas = new Canvas(drawBitmap);
    
    paint.setFilterBitmap(true);
    
    Log.d(LOG, "density background: " + background.getDensity());
    
    erasePaint = new Paint();
    erasePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
    erasePaint.setAntiAlias(true);
    // erasePaint.setAlpha(0);
    
    ovalRect = new RectF(width * x1, height * y1, width * x2, height * y2);
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:25,代码来源:Gauge.java

示例5: getRoundedCornerImage

import android.graphics.PorterDuffXfermode; //导入依赖的package包/类
public static Bitmap getRoundedCornerImage(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(), Bitmap.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 + 0.7f,finalBitmap.getHeight() / 2 + 0.7f,finalBitmap.getWidth() / 2 +                                      0.1f, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(finalBitmap, rect, rect, paint);

    return output;
}
 
开发者ID:WSAyan,项目名称:AndroidDumbStructure,代码行数:27,代码来源:ImageShaper.java

示例6: circleBitmap

import android.graphics.PorterDuffXfermode; //导入依赖的package包/类
public static Bitmap circleBitmap(Bitmap source) {
    //获取图片的宽度
    int width = source.getWidth();
    //创建一个与source等宽的Bitmap对象
    Bitmap bitmap = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888);
    //创建等大小的画布
    Canvas canvas = new Canvas(bitmap);
    //绘制一个圆圈:将此圆圈理解为下层图片
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    canvas.drawCircle(width / 2, width / 2, width / 2, paint);

    //设置图片相交情况下的处理方式
    //setXfermode:设置当绘制的图像出现相交情况时候的处理方式的,它包含的常用模式有哪几种
    //PorterDuff.Mode.SRC_IN 取两层图像交集部门,只显示上层图像,注意这里是指取相交叉的部分,然后显示上层图像
    //PorterDuff.Mode.DST_IN 取两层图像交集部门,只显示下层图像
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    //source:理解为上层图片
    canvas.drawBitmap(source, 0, 0, paint);

    return bitmap;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:BitmapUtils.java

示例7: cut2Circular

import android.graphics.PorterDuffXfermode; //导入依赖的package包/类
/**
 * 裁剪圆形图片
 *
 * @param source
 * @param recycleSource 裁剪成功后销毁原图
 * @return
 */
public static Bitmap cut2Circular(Bitmap source, boolean recycleSource) {
    int width = source.getWidth();
    int height = source.getHeight();
    int diameter = Math.min(width, height);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    Bitmap result = Bitmap.createBitmap(diameter, diameter, Bitmap.Config.ARGB_8888);
    if (result != null) {
        Canvas canvas = new Canvas(result);
        canvas.drawCircle(diameter / 2, diameter / 2, diameter / 2, paint);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(source, (diameter - width) / 2, (diameter - height) / 2, paint);
        if (recycleSource) {
            source.recycle();
            source = null;
        }
    } else {
        result = source;
    }
    return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:ImageDecoder.java

示例8: toRoundCorner

import android.graphics.PorterDuffXfermode; //导入依赖的package包/类
/**
 * 将图片变为圆角
 * @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;
}
 
开发者ID:CoderCF,项目名称:TakePhoto,代码行数:28,代码来源:FileUtil.java

示例9: toRound

import android.graphics.PorterDuffXfermode; //导入依赖的package包/类
/**
 * 转为圆形图片
 *
 * @param src     源图片
 * @param recycle 是否回收
 * @return 圆形图片
 */
public static Bitmap toRound(Bitmap src, boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    int width = src.getWidth();
    int height = src.getHeight();
    int radius = Math.min(width, height) >> 1;
    Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig());
    Paint paint = new Paint();
    Canvas canvas = new Canvas(ret);
    Rect rect = new Rect(0, 0, width, height);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle(width >> 1, height >> 1, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(src, rect, rect, paint);
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:25,代码来源:ImageUtils.java

示例10: getRoundedCornerBitmap

import android.graphics.PorterDuffXfermode; //导入依赖的package包/类
/**
 * 两张图片合成一张图片圆角的图片 . <br>
 * @author liulongzhenhai 2013-10-28 上午11:24:15 <br>
 * @param outBitmap1 背景图片
 * @param bitmap 要生成圆角的图片
 * @return Bitmap Bitmap
 */
public static Bitmap getRoundedCornerBitmap(final Bitmap outBitmap1, final Bitmap bitmap) {
	final int sm = 0;
	// Log.w("outHeight",outBitmap.getHeight()+","+outBitmap.getWidth());
	final Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
	final Canvas canvas = new Canvas(outBitmap);
	final int color = 0xff424242;
	final Paint paint = new Paint();
	final Rect rect = new Rect(sm, sm, bitmap.getWidth() - sm, bitmap.getHeight() - sm);
	final RectF rectF = new RectF(rect);
	final float roundPX = bitmap.getWidth() / 2;
	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 outBitmap;
}
 
开发者ID:VK2012,项目名称:AppCommonFrame,代码行数:26,代码来源:BitmapUtil.java

示例11: getRoundedCornerBitmap

import android.graphics.PorterDuffXfermode; //导入依赖的package包/类
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;
}
 
开发者ID:zqHero,项目名称:rongyunDemo,代码行数:27,代码来源:BitmapUtils.java

示例12: init

import android.graphics.PorterDuffXfermode; //导入依赖的package包/类
private void init(Context context, AttributeSet attrs) {
    TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.CheckBox_Sample);
    size = ta.getDimensionPixelSize(R.styleable.CheckBox_Sample_size, dp(size));
    bitmapColor = ta.getColor(R.styleable.CheckBox_Sample_color_background, bitmapColor);
    borderColor = ta.getColor(R.styleable.CheckBox_Sample_color_border, borderColor);

    bitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    bitmapEraser = new Paint(Paint.ANTI_ALIAS_FLAG);
    bitmapEraser.setColor(0);
    bitmapEraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    checkEraser = new Paint(Paint.ANTI_ALIAS_FLAG);
    checkEraser.setColor(0);
    checkEraser.setStyle(Paint.Style.STROKE);
    checkEraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    borderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    borderPaint.setStyle(Paint.Style.STROKE);
    borderPaint.setStrokeWidth(dp(2));
    checkDrawable = context.getResources().getDrawable(R.mipmap.check);
    setVisibility(VISIBLE);
    ta.recycle();
}
 
开发者ID:wendyltan,项目名称:EasyTodo,代码行数:22,代码来源:CheckBoxSample.java

示例13: getCroppedBitmap

import android.graphics.PorterDuffXfermode; //导入依赖的package包/类
private Bitmap getCroppedBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(
            bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    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.WHITE);

    final float radius =  (bitmap.getWidth() - mImageStrokePx) / 2f;
    canvas.drawCircle(bitmap.getWidth() / 2f, bitmap.getHeight() / 2f, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    paint.setColor(mImageStrokeColor);
    paint.setStyle(Paint.Style.STROKE);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC));
    paint.setStrokeWidth(mImageStrokePx);
    canvas.drawCircle(bitmap.getWidth() / 2f, bitmap.getHeight() / 2f, radius, paint);

    return output;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:26,代码来源:ProfileDataCache.java

示例14: roundCorners

import android.graphics.PorterDuffXfermode; //导入依赖的package包/类
private static Bitmap roundCorners(Bitmap bitmap, int radiusPx) {

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

        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 = radiusPx;

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

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

        return output;
    }
 
开发者ID:Adyen,项目名称:adyen-android,代码行数:20,代码来源:IconUtil.java

示例15: ShapeScrim

import android.graphics.PorterDuffXfermode; //导入依赖的package包/类
public ShapeScrim(Context context, AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);

  if (attrs != null) {
    TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ShapeScrim, 0, 0);
    String     shapeName  = typedArray.getString(R.styleable.ShapeScrim_shape);

    if      ("square".equalsIgnoreCase(shapeName)) this.shape = ShapeType.SQUARE;
    else if ("circle".equalsIgnoreCase(shapeName)) this.shape = ShapeType.CIRCLE;
    else                                           this.shape = ShapeType.SQUARE;

    this.radius = typedArray.getFloat(R.styleable.ShapeScrim_radius, 0.4f);

    typedArray.recycle();
  } else {
    this.shape  = ShapeType.SQUARE;
    this.radius = 0.4f;
  }

  this.eraser = new Paint();
  this.eraser.setColor(0xFFFFFFFF);
  this.eraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:24,代码来源:ShapeScrim.java


注:本文中的android.graphics.PorterDuffXfermode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。