mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
修复ImgUtil.convert png转jpg在jdk9+中失败问题
This commit is contained in:
parent
9866840b81
commit
f85e69ab65
@ -15,6 +15,7 @@
|
|||||||
* 【core 】 修复LocalDateTime#parseDate未判断空问题问题(issue#I8FN7F@Gitee)
|
* 【core 】 修复LocalDateTime#parseDate未判断空问题问题(issue#I8FN7F@Gitee)
|
||||||
* 【http 】 修复RootAction send404 抛异常问题(pr#1107@Gitee)
|
* 【http 】 修复RootAction send404 抛异常问题(pr#1107@Gitee)
|
||||||
* 【extra 】 修复Archiver 最后一个 Entry 为空文件夹时未关闭 Entry问题(pr#1123@Gitee)
|
* 【extra 】 修复Archiver 最后一个 Entry 为空文件夹时未关闭 Entry问题(pr#1123@Gitee)
|
||||||
|
* 【core 】 修复ImgUtil.convert png转jpg在jdk9+中失败问题(issue#I8L8UA@Gitee)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.23(2023-11-12)
|
# 5.8.23(2023-11-12)
|
||||||
|
@ -531,13 +531,7 @@ public class ImgUtil {
|
|||||||
FileUtil.copy(srcImageFile, destImageFile, true);
|
FileUtil.copy(srcImageFile, destImageFile, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageOutputStream imageOutputStream = null;
|
Img.from(srcImageFile).write(destImageFile);
|
||||||
try {
|
|
||||||
imageOutputStream = getImageOutputStream(destImageFile);
|
|
||||||
convert(read(srcImageFile), destExtName, imageOutputStream, StrUtil.equalsIgnoreCase(IMAGE_TYPE_PNG, srcExtName));
|
|
||||||
} finally {
|
|
||||||
IoUtil.close(imageOutputStream);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -560,16 +554,25 @@ public class ImgUtil {
|
|||||||
* @param srcImage 源图像流
|
* @param srcImage 源图像流
|
||||||
* @param formatName 包含格式非正式名称的 String:如JPG、JPEG、GIF等
|
* @param formatName 包含格式非正式名称的 String:如JPG、JPEG、GIF等
|
||||||
* @param destImageStream 目标图像输出流
|
* @param destImageStream 目标图像输出流
|
||||||
* @param isSrcPng 源图片是否为PNG格式
|
|
||||||
* @since 4.1.14
|
* @since 4.1.14
|
||||||
*/
|
*/
|
||||||
|
public static void convert(Image srcImage, String formatName, ImageOutputStream destImageStream) {
|
||||||
|
Img.from(srcImage).setTargetImageType(formatName).write(destImageStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图像类型转换:GIF=》JPG、GIF=》PNG、PNG=》JPG、PNG=》GIF(X)、BMP=》PNG<br>
|
||||||
|
* 此方法并不关闭流
|
||||||
|
*
|
||||||
|
* @param srcImage 源图像流
|
||||||
|
* @param formatName 包含格式非正式名称的 String:如JPG、JPEG、GIF等
|
||||||
|
* @param destImageStream 目标图像输出流
|
||||||
|
* @param isSrcPng 源图片是否为PNG格式(参数无效)
|
||||||
|
* @since 4.1.14
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public static void convert(Image srcImage, String formatName, ImageOutputStream destImageStream, boolean isSrcPng) {
|
public static void convert(Image srcImage, String formatName, ImageOutputStream destImageStream, boolean isSrcPng) {
|
||||||
final BufferedImage src = toBufferedImage(srcImage, isSrcPng ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB);
|
convert(srcImage, formatName, destImageStream);
|
||||||
try {
|
|
||||||
ImageIO.write(src, formatName, destImageStream);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new IORuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------------------------------- grey
|
// ---------------------------------------------------------------------------------------------------------------------- grey
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
package cn.hutool.core.img;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class IssueI8L8UATest {
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void convertTest() {
|
||||||
|
ImgUtil.convert(
|
||||||
|
FileUtil.file("d:/test/1.png"),
|
||||||
|
FileUtil.file("d:/test/1.jpg"));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user