samedi 2 mai 2015

Android Image view pixelation

I want to add an ImageView in my application that displays a photo that has a round overlay, so that it appears as a circle rather than a square. However, when I apply the circle overlay, the edge of the circle is pixelated. How can I change my code so that the edge of the circle isn't so jagged.

This is an example of my code at present... enter image description here

Here is my code...

public Bitmap getRoundedShape(Bitmap bitmap) {
    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 - 1) / 2,
            ((float) targetHeight - 1) / 2,
            (Math.min(((float) targetWidth),
                    ((float) targetHeight)) / 2),
            Path.Direction.CCW);

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

xml border

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://ift.tt/nIICcg"
android:shape="oval">

<stroke android:width="2dp" android:color="#fff" />
<solid android:color="@android:color/white"/>

Aucun commentaire:

Enregistrer un commentaire