标签:ar sp for bs 代码 ad as tt new
最近在安卓手机控制蓝牙打印机打印图片,有时候图片太大,考虑到bitmap的切割,在此,献上代码,各位小主指点
public class ImageSplitter {
public static ArrayList<Bitmap> split(Bitmap bitmap, int xPiece, int yPiece,int pieceWidth,int pieceHeight) {
//xPiece 要分的行数 ,yPiece 要分得列数 pieceWidth每个图片的宽度 pieceHeight每个图片的高度
ArrayList<Bitmap> pieces = new ArrayList<Bitmap>(xPiece * yPiece);
for (int i = 0; i < yPiece; i++) {
for (int j = 0; j < xPiece; j++) {
int xValue = j * pieceWidth;
int yValue = i * pieceHeight;
Bitmap piece = Bitmap.createBitmap(bitmap, xValue, yValue,
pieceWidth, pieceHeight);
pieces.add(piece);
}
}
return pieces;
}
}
标签:ar sp for bs 代码 ad as tt new
原文地址:http://www.cnblogs.com/ColdSnow/p/4165811.html