[Android, JAVA] How to fit a bitmap in a rounded square in Android Studio

Rocco Galati
Rocco Galati used Ask the Experts™
on
I'm using Android Studio and I would like to be able to pickup am image from the gallery, resize it and make it fit inside a rounded square (of about 300x300px) by maintening the correct aspect ratio. At the moment, I'm able to resize it and display it as a circle with this code:

FixBitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
                bitmap_to_save = scaleBitmapAndKeepRation(FixBitmap, 320, 320);

                RoundedBitmapDrawable roundDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap_to_save);
                roundDrawable.setCircular(true);
                p_avatar.setImageDrawable(roundDrawable);

Open in new window


However, I would like to know if it is possible to make the bitmap look like my attached image. Moreover, it would be important for me to resize the image without losing the original aspect ratio.

avatar-circle.png
It is not exactly a well square rounded figure, so I'm not sure that it is possible to do it in Android.

I hope you can help me, thanks!

EDIT: I'm using Picasso library for the moment, and it seems to work. Anyway, I would like to keep always the same picture size (300x300 px) and the aspect ratio. How can I do it?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Stacy RichardDirector of Member Experience  

Commented:
Hi,

I am following up on your question.  Do you still need help?

If you solved the problem on your own, would you please post the solution here in case others have the same problem?

Regards,

Stacy Richard
Customer Relations
Rocco GalatiR&D Engineer

Author

Commented:
I didn't solve the problem. I abandoned the question since I received no help.
I was also thinking to cancel my subscription since I usually receive insufficient support for my questions.

Regards,

RG

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial