當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。