Example usage for android.graphics Bitmap extractAlpha

List of usage examples for android.graphics Bitmap extractAlpha

Introduction

In this page you can find the example usage for android.graphics Bitmap extractAlpha.

Prototype

@CheckResult
public Bitmap extractAlpha() 

Source Link

Document

Returns a new bitmap that captures the alpha values of the original.

Usage

From source file:Main.java

public static Bitmap toAlpha(Bitmap src, Boolean recycle) {
    if (isEmptyBitmap(src))
        return null;
    Bitmap ret = src.extractAlpha();
    if (recycle && !src.isRecycled())
        src.recycle();//from  ww w.j ava  2s  .  co  m
    return ret;
}

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

public static Bitmap addShadow(Bitmap src, float radius, float dx, float dy, int shadowColor) {

    int margin = 0;
    if (radius <= 0)
        radius = 1;//from  w w w.ja  v  a2s.  co  m
    if (dx < 0)
        dx = 0;
    if (dy < 0)
        dy = 0;

    margin = (int) radius;

    Bitmap alpha = src.extractAlpha();

    Bitmap bmp = Bitmap.createBitmap(src.getWidth() + margin * 2, src.getHeight() + margin * 2,
            Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bmp);
    //LogHelper.log ("Canvas.isHardwareAccelerated() " + canvas.isHardwareAccelerated() );
    Paint paint = new Paint();
    paint.setColor(shadowColor);

    paint.setShadowLayer(radius, dx, dy, shadowColor);

    canvas.drawBitmap(alpha, margin, margin, paint);
    canvas.drawBitmap(src, margin, margin, null);

    return bmp;
}

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;//ww  w .  jav  a  2  s .co m
    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: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);/* ww  w.  j  av a2  s. c  om*/
    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();

    // The output bitmap (with the icon + glow)
    Bitmap bmp = Bitmap.createBitmap(src.getWidth() + margin, src.getHeight() + margin,
            Bitmap.Config.ARGB_8888);// www  . j  a va  2 s.  c om

    // 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);

}

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);//from w ww  . j  a  v a  2  s.  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;
}