Android 图片切割工具类
发布日期:2021-06-30 22:37:06
浏览次数:2
分类:技术文章
本文共 1689 字,大约阅读时间需要 5 分钟。
图片切割工具类
public class ImageSplitter { /** * 将图片切成 , piece *piece * * @param bitmap * @param piece * @return */ public static Listsplit(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); ListmItemBitmaps = 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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
第一次来,支持一个
[***.219.124.196]2024年04月25日 21时24分54秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Failed to connect to github.com port 443: Operation timed out和弹出无法打开"GoogleSoftwareUpdate.bundle"
2019-04-30
2021.5.19 JS高级第二天
2019-04-30
2021.5.20 JS高级第三天
2019-04-30
2021.5.21 Jquery
2019-04-30
2021.5.22 Jquery
2019-04-30
2021.5.25 JSON
2019-04-30
2021.5.25 Flex
2019-04-30
2021.5.28 AJAX
2019-04-30
正则表达式
2019-04-30
过滤器Filter
2019-04-30
2021.6.1 Array补充
2019-04-30
【收藏】Markdown笔记
2019-04-30
离散数学-图论
2019-04-30
啊沙发沙发
2019-04-30
2021-07-02
2019-04-30
「收藏」HTML笔记-持续更新中
2019-04-30
数据结构期末复习------排序汇总
2019-04-30
数据结构期末复习------查找汇总
2019-04-30
Vue学习(10)————————编程式导航,地址栏的#号去掉,路由的嵌套
2019-04-30
SpringBoot内置Tomcat配置参数
2019-04-30