split Bitmap - Android android.graphics

Android examples for android.graphics:Bitmap Operation

Description

split Bitmap

Demo Code

import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.NinePatch;
import android.graphics.drawable.NinePatchDrawable;
import java.io.ByteArrayOutputStream;

public class Main{

    public static Bitmap[] splitBitmap(Bitmap pic, int row, int col) {
        int tileWidth = pic.getWidth() / col;
        int tileHeight = pic.getHeight() / row;

        Bitmap[] tiles = new Bitmap[row * col];
        for (int r = 0; r < row; r++) {
            for (int c = 0; c < col; c++) {
                tiles[r * col + c] = Bitmap.createBitmap(pic,
                        c * tileWidth, r * tileHeight, tileWidth,
                        tileHeight);/*from   w  w  w  . j a  v  a  2s .c o m*/
            }
        }
        return tiles;
    }

}

Related Tutorials