Android 图片切割工具类
发布日期:2021-06-30 22:37:06 浏览次数:2 分类:技术文章

本文共 1689 字,大约阅读时间需要 5 分钟。

图片切割工具类

public class ImageSplitter  {
/** * 将图片切成 , piece *piece * * @param bitmap * @param piece * @return */ public static List
split(Bitmap bitmap, int piece) { List
pieces = new ArrayList
(piece * piece); int width = bitmap.getWidth(); int height = bitmap.getHeight(); Log.e("TAG", "bitmap Width = " + width + " , height = " + height); 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; int xValue = j * pieceWidth; int yValue = i * pieceWidth; imagePiece.bitmap = Bitmap.createBitmap(bitmap, xValue, yValue, pieceWidth, pieceWidth); pieces.add(imagePiece); } } return pieces; } }

图片切割实体类:

public class ImagePiece  {      public int index = 0;      public Bitmap bitmap = null;  }

使用方法:

private void initBitmap()      {          if (mBitmap == null)              mBitmap = BitmapFactory.decodeResource(getResources(),                      R.drawable.aa);         List
mItemBitmaps = ImageSplitter.split(mBitmap, mColumn); Collections.sort(mItemBitmaps, new Comparator
() { @Override public int compare(ImagePiece lhs, ImagePiece rhs) { return Math.random() > 0.5 ? 1 : -1; } }); }

转载地址:https://lovoo.blog.csdn.net/article/details/51458814 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Android 模仿flabby bird游戏开发
下一篇:C经典 联合体union

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2024年04月25日 21时24分54秒