Leave rounded android images

1

I would like to know if I would like to make the images in my app rounded out like these

I would like to know if this would be feasible, good practice

    
asked by anonymous 11.09.2014 / 16:01

1 answer

1

Try something like this:

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;
}
    
11.09.2014 / 17:45