Search in sources :

Example 66 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project SmartCampus by Vegen.

the class EaseImageView method drawDrawable.

/**
 * draw Rounded Rectangle
 *
 * @param canvas
 * @param bitmap
 */
private void drawDrawable(Canvas canvas, Bitmap bitmap) {
    Paint paint = new Paint();
    paint.setColor(0xffffffff);
    // smooths out the edges of what is being drawn
    paint.setAntiAlias(true);
    PorterDuffXfermode xfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
    // set flags
    int saveFlags = Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG;
    canvas.saveLayer(0, 0, width, height, null, saveFlags);
    if (shapeType == 1) {
        canvas.drawCircle(width / 2, height / 2, width / 2 - 1, paint);
    } else if (shapeType == 2) {
        RectF rectf = new RectF(1, 1, getWidth() - 1, getHeight() - 1);
        canvas.drawRoundRect(rectf, radius + 1, radius + 1, paint);
    }
    paint.setXfermode(xfermode);
    float scaleWidth = ((float) getWidth()) / bitmap.getWidth();
    float scaleHeight = ((float) getHeight()) / bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    // bitmap scale
    bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    canvas.drawBitmap(bitmap, 0, 0, paint);
    canvas.restore();
}
Also used : RectF(android.graphics.RectF) Matrix(android.graphics.Matrix) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 67 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project android-jigsaw-puzzle by julesbond007.

the class DrawingView method setErase.

/**
 * Set erase to true when the erase button is clicked.
 *
 * @param isErase {@code true} if erase is clicked {@code false} otherwise
 */
public void setErase(boolean isErase) {
    Xfermode xfermode = isErase ? new PorterDuffXfermode(PorterDuff.Mode.CLEAR) : null;
    drawPaint.setXfermode(xfermode);
}
Also used : PorterDuffXfermode(android.graphics.PorterDuffXfermode) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Xfermode(android.graphics.Xfermode)

Example 68 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project Offer by woshiyizhijiao.

the class ImageTools method createReflectionImageWithOrigin.

/**
 * Base64 to byte[] //
 */
// public static byte[] base64ToBytes(String base64) throws IOException {
// byte[] bytes = Base64.decode(base64);
// return bytes;
// }
// 
// /**
// * Byte[] to base64
// */
// public static String bytesTobase64(byte[] bytes) {
// String base64 = Base64.encode(bytes);
// return base64;
// }
/**
 * Create reflection images
 *
 * @param bitmap
 * @return
 */
public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) {
    final int reflectionGap = 4;
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, h / 2, w, h / 2, matrix, false);
    Bitmap bitmapWithReflection = Bitmap.createBitmap(w, (h + h / 2), Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(bitmap, 0, 0, null);
    Paint deafalutPaint = new Paint();
    canvas.drawRect(0, h, w, h + reflectionGap, deafalutPaint);
    canvas.drawBitmap(reflectionImage, 0, h + 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, h, w, bitmapWithReflection.getHeight() + reflectionGap, paint);
    return bitmapWithReflection;
}
Also used : LinearGradient(android.graphics.LinearGradient) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 69 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project KISS by Neamar.

the class IconsHandler method generateBitmap.

private Drawable generateBitmap(Drawable defaultBitmap) {
    // if no support images in the icon pack return the bitmap itself
    if (backImages.size() == 0) {
        return defaultBitmap;
    }
    // select a random background image
    Random r = new Random();
    int backImageInd = r.nextInt(backImages.size());
    Bitmap backImage = backImages.get(backImageInd);
    int w = backImage.getWidth();
    int h = backImage.getHeight();
    // create a bitmap for the result
    Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    // draw the background first
    canvas.drawBitmap(backImage, 0, 0, null);
    // scale original icon
    Bitmap scaledBitmap = Bitmap.createScaledBitmap(((BitmapDrawable) defaultBitmap).getBitmap(), (int) (w * factor), (int) (h * factor), false);
    if (maskImage != null) {
        // draw the scaled bitmap with mask
        Bitmap mutableMask = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        Canvas maskCanvas = new Canvas(mutableMask);
        maskCanvas.drawBitmap(maskImage, 0, 0, new Paint());
        // paint the bitmap with mask into the result
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
        canvas.drawBitmap(scaledBitmap, (w - scaledBitmap.getWidth()) / 2, (h - scaledBitmap.getHeight()) / 2, null);
        canvas.drawBitmap(mutableMask, 0, 0, paint);
        paint.setXfermode(null);
    } else {
        // draw the scaled bitmap without mask
        canvas.drawBitmap(scaledBitmap, (w - scaledBitmap.getWidth()) / 2, (h - scaledBitmap.getHeight()) / 2, null);
    }
    // paint the front
    if (frontImage != null) {
        canvas.drawBitmap(frontImage, 0, 0, null);
    }
    return new BitmapDrawable(iconPackres, result);
}
Also used : Bitmap(android.graphics.Bitmap) Random(java.util.Random) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Paint(android.graphics.Paint)

Example 70 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project android_frameworks_base by crdroidandroid.

the class UserIconDrawable method setBadge.

public UserIconDrawable setBadge(Drawable badge) {
    mBadge = badge;
    if (mBadge != null) {
        if (mClearPaint == null) {
            mClearPaint = new Paint();
            mClearPaint.setAntiAlias(true);
            mClearPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
            mClearPaint.setStyle(Paint.Style.FILL);
        }
        // update metrics
        onBoundsChange(getBounds());
    } else {
        invalidateSelf();
    }
    return this;
}
Also used : PorterDuffXfermode(android.graphics.PorterDuffXfermode) Paint(android.graphics.Paint)

Aggregations

PorterDuffXfermode (android.graphics.PorterDuffXfermode)152 Paint (android.graphics.Paint)127 Canvas (android.graphics.Canvas)103 Bitmap (android.graphics.Bitmap)92 Rect (android.graphics.Rect)65 RectF (android.graphics.RectF)51 Matrix (android.graphics.Matrix)11 LinearGradient (android.graphics.LinearGradient)10 SuppressLint (android.annotation.SuppressLint)9 TypedArray (android.content.res.TypedArray)8 Point (android.graphics.Point)6 IOException (java.io.IOException)6 BitmapDrawable (android.graphics.drawable.BitmapDrawable)5 ColorMatrix (android.graphics.ColorMatrix)4 Path (android.graphics.Path)4 Resources (android.content.res.Resources)3 Drawable (android.graphics.drawable.Drawable)3 ResourceHelper (com.klinker.android.launcher.api.ResourceHelper)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 RadialGradient (android.graphics.RadialGradient)2