Skip to content Skip to sidebar Skip to footer

Rounded Border Around To Bitmap

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas

Solution 1:

For PorterDuffXfermode, you have to write import android.graphics.PorterDuffXfermode;

For Config.ARGB_8888, you have to write import android.graphics.Bitmap.Config;

Otherwise Direct press CTRL + SHIFT + O to organize imports.

Solution 2:

made a oval shape xml name it to round_shape.xml

<?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval" ><strokeandroid:width="1dp"android:color="#bebebe" /></shape>

Set this xml to background of image view like below

    <ImageView
                android:id="@+id/img_profile"
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:padding="2dp"
                android:scaleType="fitXY"
                android:background="@drawable/round_shape"/>

Now you have round the bitmap and set as imagebitmap resource like this img_profile.setImageBitmap(roundBit(selected_Pic_Bitmap)); , For rounding image bitmap use below code

public Bitmap roundBit(Bitmap bm) {

BitmapcircleBitmap= Bitmap.createBitmap(bm.getWidth(),
            bm.getHeight(), Bitmap.Config.ARGB_8888);

    BitmapShadershader=newBitmapShader(bm, TileMode.CLAMP,
            TileMode.CLAMP);
    Paintpaint=newPaint();
    paint.setShader(shader);
    paint.setAntiAlias(true);
    Canvasc=newCanvas(circleBitmap);

    c.drawCircle(bm.getWidth() / 2, bm.getHeight() / 2, bm.getWidth() / 2,
            paint);

    return circleBitmap;
}

round_image_with_border

Post a Comment for "Rounded Border Around To Bitmap"