0

I looked up to make images round. This worked but the image is not completely round...

Round image

What can i do so that the image take the full imageview. android:scaleType="fitXY" did not work.

This is the code to make the image round:

public Bitmap getRoundedShape(Bitmap scaleBitmapImage) {
    // TODO Auto-generated method stub
    int targetWidth = 150;
    int targetHeight = 150;
    Bitmap targetBitmap = Bitmap.createBitmap(targetWidth,
            targetHeight,Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(targetBitmap);
    Path path = new Path();
    path.addCircle(((float) targetWidth - 1) / 2,
            ((float) targetHeight - 1) / 2,
            (Math.min(((float) targetWidth),
                    ((float) targetHeight)) / 2),
            Path.Direction.CCW);

    canvas.clipPath(path);
    Bitmap sourceBitmap = scaleBitmapImage;
    canvas.drawBitmap(sourceBitmap,
            new Rect(0, 0, sourceBitmap.getWidth(),
                    sourceBitmap.getHeight()),
            new Rect(0, 0, targetWidth,
                    targetHeight), null);
    return targetBitmap;
}

When adding dividing by 2

enter image description here

My XML:

<ImageView
    android:layout_width="120dp"
    app:srcCompat="@drawable/round_image"
    android:id="@+id/imageView"
    android:background="@drawable/round_image"
    android:layout_height="120dp"
    android:layout_below="@+id/lblEmail"
    android:layout_centerHorizontal="true" />

<ImageView
    android:layout_width="120dp"
    app:srcCompat="@mipmap/profiel_dark"
    android:id="@+id/ivProfilePic"
    android:layout_height="120dp"
    android:layout_below="@+id/lblEmail"
    android:layout_alignLeft="@+id/imageView"
    android:layout_alignStart="@+id/imageView"
    android:padding="5dp" />
Joris
  • 119
  • 9

0 Answers0