Crop Image Android Tutorial – Pick and Crop Image in Android

Hello everyone, here I bring you this Crop Image Android Tutorial in which you will learn how to implement image picker and cropper. This utillity can be used for configuring Profile Images or some image …

crop image android tutorial

Hello everyone, here I bring you this Crop Image Android Tutorial in which you will learn how to implement image picker and cropper. This utillity can be used for configuring Profile Images or some image related tasks where you need to pick any image from gallery or camera and then get a cropped image out of it. So, without wasting any time, let’s get started.

The output of this Crop Image Android Tutorial may be seen in the below images.

crop image android tutorial

Crop Image Android Tutorial

Creating new Project

  • Begin with creating a new Android Studio Project. As the gradle is built and the files get loaded, we are good to import the library required to achieve the  utility. To do so,

Adding Library

  • Add the line below to your Project level gradle

  • and add the line below to your app level gradle and sync it:-

  • Now that the library has been imported.

Creating Interface

  • Its time to configure the activity_main.xml and MainActivity.java.
  • Here’s the activity_main.xml. It consists of an imageButton where you can tap on to load your profile picture and some textViews to display some profile information.
  • So, go ahead and add the following code to your activity_main.xml.

Coding the Activity

  • Now that the layout is configured, we shall configure the MainActivity.java.
  • Here’s the MainActivity.java. It consists of methods to initiate the image selection, request permissions, handling the cropping activity and all. So, go ahead and add the following code to your MainActivity.java:-

  • Next, we need an image to be displayed in the imageButton by default. To do so, save the image below  and add it to the  drawable folder of your project(filename must remain same).

profile

 

  • Great. We are almost done. Just update your AndroidManifest.xml with the one shown below:-

  • And you did it. Now run the project and tap on the profile image button. A pop up shall come up asking your to choose between Camera and Gallery. As you do and select the image, it shall take you to the CropImagActivity. Once cropped, it will return to the MainActivity with the cropped image set to the imageButton.

So thats all for this crop image android tutorial. If you are having any troubles regarding this crop image android tutorial the lets meet in the comment section to sort out the problems. Thank You 🙂

Hello, I am Manish Kumar. I am a B.Tech Student at NIT Jamshedpur. Fortunately, I find myself quite passionate about Computers and Technology. Android is my most recent Crush.

Expand Your Knowledge: Next Tutorial Picks

1 1 vote
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x