Wednesday, April 25, 2012

SPLITTING/DIVIDING AN IMAGE INTO SMALLER CHUNKS/PIECES IN ANDROID


Where We Need This?

         
              In a device like SmartPhone, we know that memory management is a serious issue. So in these kind of platforms, if we want to send images to network, we may need to divide the source image into number of small chunks and then send them one by one. This concept also helps us developing a puzzle like application.


How To Achieve This?

           
              Well there are many ways to achieve this, but I prefer Bitmap API the most to achieve this. You can get more information about bitmaps from here.

Source Code:


The below code snippet shows how to split/divide an image into number of smaller chunks/pieces.




The above class has splitImage method which takes two arguments:
  1. ImageView: The source image to split.
  2. int: The number of smaller chunks to be formed from the source image.

Reference:


You can find the complete source of this application from My Google Drive Account.
If you want the same in Java using ImageIO, then you can see this



Image Before Split

Before Split

Image After Split

After Split