You've already forked FrameTour-BE
feat(image): 添加打印机默认水印操作器并优化图片处理逻辑- 新增 PrinterDefaultWatermarkOperator 实现自定义水印处理
- 在 ImageWatermarkOperatorEnum 中添加 PRINTER_DEFAULT 类型 - 更新 ImageWatermarkFactory 以支持新的水印操作器 - 调整日期格式为 yyyy.MM.dd 用于打印场景 -优化 ImageUtils 中的图片旋转逻辑,仅支持270度旋转 - 移除对90度旋转的支持以简化处理流程
This commit is contained in:
@@ -287,10 +287,9 @@ public class ImageUtils {
|
||||
best.rotationDegrees = 0;
|
||||
best.pixelsLost = Integer.MAX_VALUE;
|
||||
|
||||
// 测试三种情况: 不旋转、旋转90度、旋转270度
|
||||
// 测试两种情况: 不旋转、旋转270度
|
||||
int[][] scenarios = {
|
||||
{0, srcWidth, srcHeight}, // 不旋转
|
||||
{90, srcHeight, srcWidth}, // 旋转90度
|
||||
{270, srcHeight, srcWidth} // 旋转270度
|
||||
};
|
||||
|
||||
@@ -331,35 +330,28 @@ public class ImageUtils {
|
||||
return source;
|
||||
}
|
||||
|
||||
if (degrees != 270) {
|
||||
throw new IllegalArgumentException("仅支持270度旋转");
|
||||
}
|
||||
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
|
||||
// 90度和270度会交换宽高
|
||||
BufferedImage rotated;
|
||||
|
||||
// 270度会交换宽高
|
||||
BufferedImage rotated = new BufferedImage(height, width, source.getType());
|
||||
Graphics2D g2d = null;
|
||||
|
||||
|
||||
try {
|
||||
if (degrees == 90 || degrees == 270) {
|
||||
rotated = new BufferedImage(height, width, source.getType());
|
||||
g2d = rotated.createGraphics();
|
||||
|
||||
AffineTransform transform = new AffineTransform();
|
||||
if (degrees == 90) {
|
||||
transform.translate(height / 2.0, width / 2.0);
|
||||
transform.rotate(Math.PI / 2);
|
||||
transform.translate(-width / 2.0, -height / 2.0);
|
||||
} else { // 270度
|
||||
transform.translate(height / 2.0, width / 2.0);
|
||||
transform.rotate(-Math.PI / 2);
|
||||
transform.translate(-width / 2.0, -height / 2.0);
|
||||
}
|
||||
|
||||
g2d.setTransform(transform);
|
||||
g2d.drawImage(source, 0, 0, null);
|
||||
} else {
|
||||
throw new IllegalArgumentException("仅支持90度和270度旋转");
|
||||
}
|
||||
|
||||
g2d = rotated.createGraphics();
|
||||
|
||||
AffineTransform transform = new AffineTransform();
|
||||
transform.translate(height / 2.0, width / 2.0);
|
||||
transform.rotate(-Math.PI / 2);
|
||||
transform.translate(-width / 2.0, -height / 2.0);
|
||||
|
||||
g2d.setTransform(transform);
|
||||
g2d.drawImage(source, 0, 0, null);
|
||||
|
||||
return rotated;
|
||||
} finally {
|
||||
if (g2d != null) {
|
||||
|
||||
Reference in New Issue
Block a user