根据老师的代码打,出现错误了,也不知道水木情况。
根据老师的代码打,出现错误了,也不知道水木情况。
package com.imooc.game.utils;
import android.graphics.Bitmap;
public class ImagePiece
{
private int index;
private Bitmap bitmap;
public ImagePiece()
{
}
public ImagePiece(int index,Bitmap bitmap)
{
this.index = index;
this.bitmap = bitmap;
}
@Override
public String toString()
{
return "ImagePiece [index=" + index + ",bitma
}
}
package com.imooc.game.utils;
import java.util.ArrayList;
import java.util.List;
import android.graphics.Bitmap;
public class ImageSplitterUtil
{
/**
* @param bitmap
* @param piece
* 切成piece*piece块
* @return List<ImagePiece>
*/
public static List<ImagePiece> splitImage(Bitmap bitmap, int piece)
{
List<ImagePiece> imagePieces = new ArrayList<ImagePiece>();
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int pieceWidth = Math.min(width, height) / piece;
for (int i = 0; i < piece; i++)
{
for (int j = 0; j < piece; j++)
{
ImagePiece imagePiece = new ImagePiece();
imagePiece.setIndex(j + i * piece);
int x = j * pieceWidth;
int y = i * pieceWidth;
imagePiece.setBitmap(Bitmap.createBitmap(bitmap, x, y,
pieceWidth, pieceWidth));
imagePieces.add(imagePiece);
}
}
return imagePieces;
}
}