mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
!793 修复图片分割方法ImgUtil.sliceByRowsAndCols()导致分割后图片失真问题
Merge pull request !793 from 小白仙人/v5-master
This commit is contained in:
commit
366a0e5c93
@ -439,12 +439,13 @@ public class ImgUtil {
|
||||
*
|
||||
* @param srcImageFile 源图像文件
|
||||
* @param destDir 切片目标文件夹
|
||||
* @param format 目标文件格式
|
||||
* @param rows 目标切片行数。默认2,必须是范围 [1, 20] 之内
|
||||
* @param cols 目标切片列数。默认2,必须是范围 [1, 20] 之内
|
||||
*/
|
||||
public static void sliceByRowsAndCols(File srcImageFile, File destDir, int rows, int cols) {
|
||||
public static void sliceByRowsAndCols(File srcImageFile, File destDir, String format, int rows, int cols) {
|
||||
try {
|
||||
sliceByRowsAndCols(ImageIO.read(srcImageFile), destDir, rows, cols);
|
||||
sliceByRowsAndCols(ImageIO.read(srcImageFile), destDir, format, rows, cols);
|
||||
} catch (IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
@ -455,10 +456,11 @@ public class ImgUtil {
|
||||
*
|
||||
* @param srcImage 源图像,如果非{@link BufferedImage},则默认使用RGB模式
|
||||
* @param destDir 切片目标文件夹
|
||||
* @param format 目标文件格式
|
||||
* @param rows 目标切片行数。默认2,必须是范围 [1, 20] 之内
|
||||
* @param cols 目标切片列数。默认2,必须是范围 [1, 20] 之内
|
||||
*/
|
||||
public static void sliceByRowsAndCols(Image srcImage, File destDir, int rows, int cols) {
|
||||
public static void sliceByRowsAndCols(Image srcImage, File destDir, String format, int rows, int cols) {
|
||||
if (false == destDir.exists()) {
|
||||
FileUtil.mkdir(destDir);
|
||||
} else if (false == destDir.isDirectory()) {
|
||||
@ -486,7 +488,7 @@ public class ImgUtil {
|
||||
for (int j = 0; j < cols; j++) {
|
||||
tag = cut(bi, new Rectangle(j * destWidth, i * destHeight, destWidth, destHeight));
|
||||
// 输出为文件
|
||||
ImageIO.write(toRenderedImage(tag), IMAGE_TYPE_JPEG, new File(destDir, "_r" + i + "_c" + j + ".jpg"));
|
||||
ImageIO.write(toRenderedImage(tag), format, new File(destDir, "_r" + i + "_c" + j + "." + format));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -89,7 +89,7 @@ public class ImgUtilTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void sliceByRowsAndColsTest() {
|
||||
ImgUtil.sliceByRowsAndCols(FileUtil.file("d:/test/logo.jpg"), FileUtil.file("d:/test/dest"), 1, 5);
|
||||
ImgUtil.sliceByRowsAndCols(FileUtil.file("d:/temp/2.png"), FileUtil.file("d:/temp/slice/png"),ImgUtil.IMAGE_TYPE_PNG, 1, 5);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user