I have 1 circular imageview and I want to place bitmap inside the imageview. but when I set the compressed bitmap image it is always rectangle. Please help me to set bitmap in circular imageview.
Thanks
I am curious about how you created a circular ImageView. Can you share that secret ?? As far as creating a circular Bitmap is concerned, create a BitmapShader from the bitmap you want to show. Then create a ShapeDrawable (Oval) and assign the bitmap shader to it. Draw the drawable. Bam! circular image!
Bitmap bitmap = getthebitmapyouwanttoshowinacirclefromsomewhere;
Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader (bitmap, TileMode.CLAMP, TileMode.CLAMP);
Paint paint = new Paint();
paint.setShader(shader);
paint.setAntiAlias(true);
Canvas c = new Canvas(circleBitmap);
c.drawCircle(bitmap.getWidth()/2, bitmap.getHeight()/2, bitmap.getWidth()/2, paint);
myImageView.setImageBitmap(circleBitmap);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With