日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > java >内容正文

java

Java_图片切片

發(fā)布時(shí)間:2024/4/15 java 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java_图片切片 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
package com.creditease.fetch.credit.util.similarity;import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.List;/*** 圖片切割工具類(lèi)*/ public class ImageCuter {/*** 切割圖片** @param image 源文件* @param width 切片寬度* @param height 切片高度* @param rowsLimit 縱向切片總數(shù)* @param colsLimit 橫向切片總數(shù)* @return* @throws Exception*/public static List<BufferedImage> cut(BufferedImage image, int width, int height, Integer rowsLimit, Integer colsLimit){List<BufferedImage> list = new ArrayList<>();int sWidth = image.getWidth(); // 圖片寬度int sHeight = image.getHeight(); // 圖片高度if (sWidth > width && sHeight > height) {int cols = 0; // 橫向切片總數(shù)int rows = 0; // 縱向切片總數(shù)int eWidth = 0; // 末端切片寬度int eHeight = 0; // 末端切片高度if (sWidth % width == 0) {cols = sWidth / width;} else {eWidth = sWidth % width;cols = sWidth / width + 1;}if (sHeight % height == 0) {rows = sHeight / height;} else {eHeight = sHeight % height;rows = sHeight / height + 1;}if (rowsLimit != null) {rows = rowsLimit;}if (colsLimit != null) {cols = colsLimit;}BufferedImage subImage = null;int cWidth = 0; // 當(dāng)前切片寬度int cHeight = 0; // 當(dāng)前切片高度for (int i = 0; i < rows; i++) {for (int j = 0; j < cols; j++) {cWidth = getWidth(j, cols, eWidth, width);cHeight = getHeight(i, rows, eHeight, height);// x坐標(biāo),y坐標(biāo),寬度,高度subImage = image.getSubimage(j * width, i * height, cWidth,cHeight);list.add(subImage);}}}return list;}/*** 獲取當(dāng)前切片的寬度** @param index 橫向索引* @param cols 橫向切片總數(shù)* @param endWidth 末端切片寬度* @param width 切片寬度* @return*/private static int getWidth(int index, int cols, int endWidth, int width) {if (index == cols - 1) {if (endWidth != 0) {return endWidth;}}return width;}/*** 獲取當(dāng)前切片的高度** @param index 縱向索引* @param rows 縱向切片總數(shù)* @param endHeight 末端切片高度* @param height 切片高度* @return*/private static int getHeight(int index, int rows, int endHeight, int height) {if (index == rows - 1) {if (endHeight != 0) {return endHeight;}}return height;}public static void main(String[] args) { // ImageCuter imageCuter = new ImageCuter(); // try { // imageCuter.cut(new File("t5.jpg"), "E:\\test2\\", 16, 16); // // } catch (Exception e) { // e.printStackTrace(); // } } }

?

轉(zhuǎn)載于:https://www.cnblogs.com/gisblogs/p/6823949.html

總結(jié)

以上是生活随笔為你收集整理的Java_图片切片的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。