Example usage for android.graphics Paint setMaskFilter

List of usage examples for android.graphics Paint setMaskFilter

Introduction

In this page you can find the example usage for android.graphics Paint setMaskFilter.

Prototype

public MaskFilter setMaskFilter(MaskFilter maskfilter) 

Source Link

Document

Set or clear the maskfilter object.

Usage

From source file:Main.java

public static Bitmap setShadow(Bitmap bitmap, int radius) {
    BlurMaskFilter blurFilter = new BlurMaskFilter(radius, BlurMaskFilter.Blur.OUTER);
    Paint shadowPaint = new Paint();
    shadowPaint.setAlpha(50);/* w  ww .j a v  a  2  s . co  m*/
    shadowPaint.setColor(0xff424242);
    shadowPaint.setMaskFilter(blurFilter);
    int[] offsetXY = new int[2];
    Bitmap shadowBitmap = bitmap.extractAlpha(shadowPaint, offsetXY);
    Bitmap shadowImage32 = shadowBitmap.copy(Bitmap.Config.ARGB_8888, true);
    Canvas c = new Canvas(shadowImage32);
    c.drawBitmap(bitmap, -offsetXY[0], -offsetXY[1], null);
    return shadowImage32;
}

From source file:com.tafayor.selfcamerashot.taflib.helpers.GraphicsHelper.java

public static Bitmap addGlow(Bitmap src, int glowColor, float radius) {
    float DEFAULT_GLOW_RADIUS_FACTOR = 0.1f;
    // An added margin to the initial image
    int margin;// w  w  w  .jav a  2  s. c  om
    int glowRadius;

    int midSize = (src.getWidth() + src.getHeight()) / 2;

    if (radius > 0 && radius < 1)
        glowRadius = (int) (midSize * radius);
    else if (radius >= 1)
        glowRadius = (int) radius;
    else
        glowRadius = (int) (midSize * DEFAULT_GLOW_RADIUS_FACTOR);

    margin = (int) (glowRadius);

    Bitmap alpha = src.extractAlpha();

    // The output bitmap (with the icon + glow)
    Bitmap bmp = Bitmap.createBitmap(src.getWidth() + margin * 2, src.getHeight() + margin * 2,
            Bitmap.Config.ARGB_8888);

    //LogHelper.log("glow new size : " + (src.getWidth() + margin*2));
    // The canvas to paint on the image
    Canvas canvas = new Canvas(bmp);

    Paint paint = new Paint();
    paint.setColor(glowColor);

    // outer glow
    paint.setMaskFilter(new BlurMaskFilter(glowRadius, BlurMaskFilter.Blur.OUTER));
    canvas.drawBitmap(alpha, margin, margin, paint);

    // original icon
    canvas.drawBitmap(src, margin, margin, null);

    return bmp;
}

From source file:com.androidmapsextensions.DefaultClusterOptionsProvider.java

private Paint createCirclePaint(Resources resources) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    blurRadius = resources.getDimension(R.dimen.ame_default_cluster_circle_blur_radius);
    if (blurRadius > 0.0f) {
        BlurMaskFilter maskFilter = new BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.SOLID);
        paint.setMaskFilter(maskFilter);
    }/*from www  .  jav a 2s.c  o  m*/
    return paint;
}

From source file:org.catrobat.catroid.ui.fragment.AddBrickFragment.java

public ImageView getGlowingBorder(Bitmap bitmap) {
    ImageView imageView = new ImageView(getActivity());
    imageView.setBackgroundColor(Color.TRANSPARENT);
    imageView.setId(R.id.drag_and_drop_list_view_image_view);

    Bitmap glowingBitmap = Bitmap.createBitmap(bitmap.getWidth() + 30, bitmap.getHeight() + 30,
            Bitmap.Config.ARGB_8888);/*from  w w  w .  ja  v  a2s.c  o  m*/
    Canvas glowingCanvas = new Canvas(glowingBitmap);
    Bitmap alpha = bitmap.extractAlpha();
    Paint paintBlur = new Paint();
    paintBlur.setColor(Color.WHITE);
    glowingCanvas.drawBitmap(alpha, 15, 15, paintBlur);
    BlurMaskFilter blurMaskFilter = new BlurMaskFilter(15.0f, BlurMaskFilter.Blur.OUTER);
    paintBlur.setMaskFilter(blurMaskFilter);
    glowingCanvas.drawBitmap(alpha, 15, 15, paintBlur);
    paintBlur.setMaskFilter(null);
    glowingCanvas.drawBitmap(bitmap, 15, 15, paintBlur);

    imageView.setImageBitmap(glowingBitmap);

    return imageView;
}

From source file:hku.fyp14017.blencode.ui.fragment.AddBrickFragment.java

public ImageView getGlowingBorder(Bitmap bitmap) {
    ImageView imageView = new ImageView(getActivity());
    imageView.setBackgroundColor(Color.TRANSPARENT);
    imageView.setId(hku.fyp14017.blencode.R.id.drag_and_drop_list_view_image_view);

    Bitmap glowingBitmap = Bitmap.createBitmap(bitmap.getWidth() + 30, bitmap.getHeight() + 30,
            Bitmap.Config.ARGB_8888);/*w  w  w  .j a va 2s  . c  o m*/
    Canvas glowingCanvas = new Canvas(glowingBitmap);
    Bitmap alpha = bitmap.extractAlpha();
    Paint paintBlur = new Paint();
    paintBlur.setColor(Color.WHITE);
    glowingCanvas.drawBitmap(alpha, 15, 15, paintBlur);
    BlurMaskFilter blurMaskFilter = new BlurMaskFilter(15.0f, BlurMaskFilter.Blur.OUTER);
    paintBlur.setMaskFilter(blurMaskFilter);
    glowingCanvas.drawBitmap(alpha, 15, 15, paintBlur);
    paintBlur.setMaskFilter(null);
    glowingCanvas.drawBitmap(bitmap, 15, 15, paintBlur);

    imageView.setImageBitmap(glowingBitmap);

    return imageView;
}

From source file:Steps.StepsFragment.java

private void setBackgroundGlow(ImageView imgview, int imageicon, int r, int g, int b) {
    // An added margin to the initial image
    int margin = 50;
    int halfMargin = margin / 2;
    // the glow radius
    int glowRadius = 90;

    // the glow color
    int glowColor = Color.rgb(r, g, b);

    // The original image to use reduced(re-sampled)
    Bitmap src = SampleImage.decodeSampledBitmapFromResource(getResources(), imageicon, 250, 250);

    // extract the alpha from the source image
    Bitmap alpha = src.extractAlpha();/*from www. ja  va2s . com*/

    // The output bitmap (with the icon + glow)
    Bitmap bmp = Bitmap.createBitmap(src.getWidth() + margin, src.getHeight() + margin,
            Bitmap.Config.ARGB_8888);

    // The canvas to paint on the image
    Canvas canvas = new Canvas(bmp);

    Paint paint = new Paint();
    paint.setColor(glowColor);

    // outer glow
    paint.setMaskFilter(new BlurMaskFilter(glowRadius, BlurMaskFilter.Blur.OUTER));//For Inner glow set Blur.INNER
    canvas.drawBitmap(alpha, halfMargin, halfMargin, paint);

    // original icon
    canvas.drawBitmap(src, halfMargin, halfMargin, null);

    imgview.setImageBitmap(bmp);

}