2

I am making an app that among functionalities, it takes an image from Facebook through URL, decodes it through Bitmap, then rounds the Bitmap in a circle, and puts it in an imageView.

The problem is that it continues to be pixelated, as shown here:

enter image description here

Here is my code:

Layout of the imageView:

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="56dp">

    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/imageView_signUpConfirmedEditProfileLayout_profilePictureHolder"
        android:layout_centerInParent="true"
        android:src="@drawable/plus_lg"/>

    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/imageView_signUpConfirmedEditProfileLayout_profilePicture"
        android:visibility="invisible"
        android:layout_centerInParent="true"/>

    <ProgressBar
        android:id="@+id/progressBar_signUpConfirmedEditProfileLayout_profilePictureProgressBar"
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_centerInParent="true"
        android:visibility="visible"/>
</RelativeLayout>

Here is rounding bitmap method:

public Bitmap getRoundedShape(Bitmap scaleBitmapImage) {
    int targetWidth = 100;
    int targetHeight = 100;
    Bitmap targetBitmap = Bitmap.createBitmap(targetWidth,
            targetHeight,Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(targetBitmap);
    Path path = new Path();
    path.addCircle(((float) targetWidth) / 2,
            ((float) targetHeight) / 2,
            (Math.min(((float) targetWidth),
                    ((float) targetHeight)) / 2),
            Path.Direction.CCW);
    canvas.clipPath(path);
    Bitmap sourceBitmap = scaleBitmapImage;
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setFilterBitmap(true);
    //paint.setColor(Color.WHITE);
    //paint.setStyle(Paint.Style.STROKE);
    //paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    //paint.setDither(true);
    //paint.setShader(new BitmapShader(sourceBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
    canvas.drawBitmap(sourceBitmap,
            new Rect(0, 0, sourceBitmap.getWidth(),
                    sourceBitmap.getHeight()),
            new Rect(0, 0, targetWidth, targetHeight), paint);
    return targetBitmap;
}

As you can see, i have tried alot, judging by the amount of lines commented, hehe.

Is there any resolve to this? I was thinking maybe i can add a border somehow that clips 1 pixel of the margin? But i don't know how to do that!

Can someone help me? Cheers!

Vlad Iancu
  • 487
  • 1
  • 6
  • 15

1 Answers1

0

Try to transform a bigger bitmap to a circle, then scale it / make it smaller.

So, download the image, enlarge it to 2-4 times the size, make the circle, then scale it back to the original size.

Here is how you scale bitmaps: Android Bitmap resize

Community
  • 1
  • 1
Alexanus
  • 679
  • 4
  • 22