Leave pictures rounded android

Asked

Viewed 71 times

1

I wonder if there was a way I could make my app images round like these inserir a descrição da imagem aqui

and wonder if that would be feasible, good practice

  • Take a look at this question: http://stackoverflow.com/questions/2459916/how-to-make-an-imageview-to-have-rounded-corners.

1 answer

1

Try something like that:

private setBitmapRounded(){
    Bitmap image = BitmapFactory.decodeResource(getResources(),
            R.drawable.img_qualquer);
    ImageView mImageView = (ImageView) findViewById(R.id.mImageResId);
    mImageView.setImageBitmap(getRoundedShape(image));
}

private Bitmap getRoundedShape(Bitmap bitmapImage) {
    //Tamanho que será seu círculo
    //Pode deixar valor estático ou usar o tamanho original da sua imagem
    int width = 150;
    int height = 150;
    Bitmap targetBitmap = Bitmap.createBitmap(width,
            height,Bitmap.Config.ARGB_8888);

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

    canvas.clipPath(path);
    Bitmap sourceBitmap = bitmapImage;
    canvas.drawBitmap(sourceBitmap,
            new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()),
            new Rect(0, 0, width, height), null);
    return targetBitmap;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.