Android图片操作-切割
/** * 图片切割方法 * @param bitmap 图片 * @param xPiece 行 * @param yPiece 列 * @return */ 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; }
ImagePiece代码
/** * 此类保存了一个Bitmap对象和一个标识图片的顺序索引的int变量 * * @author lenovo * */ public class ImagePiece { public int index = 0; public Bitmap bitmap = null; }