How to smooth the irregular borders of png bitmap

0

I am trying to smooth the borders of png image like this.

Before After

I have tried a lot but I cannot figure it out how to do it. These links did not helped much ( https://medium.com/@ali.muzaffar/android-why-your-canvas-shapes-arent-smooth-aa2a3f450eb5 ) and ( android: smooth out edges of random shape bitmap ).

I have standard ImageView to show images, and a png bitmap whose some parts are transparent. I have tried the following code but it did not help.

public Bitmap getSmooth1(Bitmap bitmap) {

    Paint mPaint = new Paint();

    BitmapShader bitmapShader = new BitmapShader(bitmap,
            Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    Matrix m = new Matrix();
    m.postTranslate(0, 1);
    bitmapShader.setLocalMatrix(m);

    final LinearGradient AAshader = new LinearGradient(0, 0, 0, 6, 0x00000000, 0xffffffff, Shader.TileMode.CLAMP);

    ComposeShader compositor = new ComposeShader(bitmapShader,
            AAshader, PorterDuff.Mode.DST_IN);

    mPaint.setShader(compositor);
    canvas.drawRect(0.0f, 0.0f, canvas.getWidth() , canvas.getHeight() , mPaint);

    return bitmap;

}

Please help me how should I achieve it. Thanks.

android
android-bitmap
smoothing
asked on Stack Overflow Sep 14, 2019 by Muhammad Rafique • edited Sep 14, 2019 by Muhammad Rafique

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0