Tuesday, September 2, 2014

Android Image Cropping - Changing Template Instructions

A year ago I posted on my blog about my image cropping algorithm that developers can use freely for their own applications. During this time I have received many requests on changing template to their own custom templates, which many of them faced identical issues when modifying code to adapt to their custom templates. Therefore, in this post I will provide a step-by-step process on how to make the necessary changes when you plan to add your own custom templates.




Setting Up Project with your Templates

For this image crop algorithm to successfully work, you must provide templates with the background transparent and the lines clearly outlining your template. Make sure this template is saved as PNG, otherwise you won't have the transparent background that is required.
Once you have your templates in PNG files, you now need to place them into the correct project folders.
Looking at the screenshot above, I've placed my templates under res/drawable-nodpi. If you created your templates meant for any screen resolutions, then you can just place it under res/drawable-nodpi. Otherwise if you made different template sizes for different screen densities, then place them in their respective drawable folders.

Making the Proper Code Changes

The next process is to write code that will crop the images that you need.
Looking at the code snippet I have posted above.  The only code that you will need to modify are the arguments for invoking the static method ImageProcess.cropImage(). In the last two arguments, you must provide it with the width and height of your template. Passing in the incorrect argument can produce an error within the application.

That is pretty much it for making the proper modifications to add your own templates. If you have any questions and/or facing issues, feel free to comment below or create a Github issue.

Cheers!!

Link to my Github project: android-cropping-example.
Link to previous blog post: Android Image Cropping Example