码迷,mamicode.com
首页 > 移动开发 > 详细

Android 将图片平均切割成多张小片

时间:2015-08-05 18:08:54      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

public class ImageSplitter
{
    /**
     * 将图片切成 , piece *piece
     * 
     * @param bitmap
     * @param piece
     * @return
     */
    public static List<ImagePiece> split(Bitmap bitmap, int piece)
    {

        List<ImagePiece> pieces = new ArrayList<ImagePiece>(piece * piece);

        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.index = j + i * piece;
                
                Log.e("TAG", "imagePiece.index" + (j + i * piece));
                
                int xValue = j * pieceWidth;
                int yValue = i * pieceWidth;
                
                imagePiece.bitmap = Bitmap.createBitmap(bitmap, xValue, yValue,
                        pieceWidth, pieceWidth);
                pieces.add(imagePiece);
            }
        }
        return pieces;
    }
}

 

Android 将图片平均切割成多张小片

标签:

原文地址:http://www.cnblogs.com/xbx2015/p/4705226.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!