How To Rotate An Image In Android – Example Code

Let’s learn how to rotate an image in android. Perhaps one of your requirements is to display rotated images in your latest android app and you just want to get that done so you can move on to other important things like taking over the world. In this post, I will show just that. As you step through this code, I would urge you to read it carefully and see if you can notice anything good or bad about its readability. I try to improve everyday as I lean towards writing clean code. Please be my judge – I will not strangle you!


How To Rotate An Image In Android – Code Sample

Let us create a simple class that I will call

What Just Happened Here?

Good question. First of all, this class is meant to be reusable. It also does several things;

  • Gets an Image File and rotates/flips it depending on the direction needed
  • It also resizes the image using a scale factor passed in. Pass 1 to keep original size.
  • It then, using the destination folder passed in, saves the finished image in disk

Testing ImageProcessor Class

I would like, with all due respect, to give Scott (my co-worker) credit for his contribution to this piece of code on how to rotate an image in android. Thank you Scott!

That is it for this post. I really wanted to make this shorter than it already is. It is time for me to go for a run and so I hope you found this post helpful. Please share it with your friends using the buttons below. Thanks and stay awesome.

Written By Elisha Chirchir

Elisha Chirchir is a software developer. He is also the founder of Simple Developer and co-founder of Instinctive Software Solutions. On any given day, he works on both Android and Web Development. During his 'free time', he offers training to those interested in learning how to code in php, java, python, javaScript etc. You can easily find him on StackOverflow Android chatroom or on Twitter @Eenvincible

3 Comments on “How To Rotate An Image In Android – Example Code

  1. erum Reply

    December 18, 2014 at 5:12

    how can i only rotate image by giving selected path i dnt want to save rotate images how can i do

  2. Israa Reply

    August 5, 2015 at 12:28

    Thank you. You helped me.

Leave a Reply

Your email address will not be published. Required fields are marked *

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