Here are two packaged classes that enable you to cut pictures. For reference and study only.
One is the Imagepiece class, which holds a bitmap object and an int variable that identifies the sequential index of the picture.
Copy Code code as follows:
Package arui319.blog.csdn.net;
Import Android.graphics.Bitmap;
public class Imagepiece {
public int index = 0;
Public Bitmap Bitmap = null;
}
One is the Imagesplitter class, which has a static method for split, and the incoming parameter is the bitmap object to be cut, and the number of horizontal and vertical cutting pieces. For example, the incoming is 3, 3, then all cut into 3, will eventually cut the entire picture into 3x3=9 slices.
Copy Code code as follows:
Package arui319.blog.csdn.net;
Import java.util.ArrayList;
Import java.util.List;
Import Android.graphics.Bitmap;
public class Imagesplitter {
public static list<imagepiece> Split (Bitmap Bitmap, int xpiece, int ypiece) {
list<imagepiece> pieces = new Arraylist<imagepiece> (xpiece * ypiece);
int width = bitmap.getwidth ();
int height = bitmap.getheight ();
int piecewidth = WIDTH/3;
int pieceheight = HEIGHT/3;
for (int i = 0; i < ypiece; i++) {
for (int j = 0; J < Xpiece; J + +) {
Imagepiece piece = new Imagepiece ();
Piece.index = j + i * xpiece;
int xvalue = J * Piecewidth;
int yvalue = i * pieceheight;
Piece.bitmap = Bitmap.createbitmap (Bitmap, Xvalue, Yvalue,
Piecewidth, Pieceheight);
Pieces.add (piece);
}
}
return pieces;
}
}
Here the cutting, mainly using the bitmap object of the CreateBitmap method, no longer do a specific description.