|
|
@ -10,6 +10,7 @@ import java.io.IOException; |
|
|
|
import java.net.URL; |
|
|
|
import java.util.Base64; |
|
|
|
|
|
|
|
|
|
|
|
public class ImageRotator { |
|
|
|
|
|
|
|
/** |
|
|
@ -21,6 +22,7 @@ public class ImageRotator { |
|
|
|
*/ |
|
|
|
public static String rotateAndOverlayImage(String sourceImagePath, String targetImagePath, double angle) { |
|
|
|
try { |
|
|
|
|
|
|
|
URL resourceUrl = ImageRotator.class.getClassLoader().getResource("templates/1.png"); |
|
|
|
URL targetUrl = ImageRotator.class.getClassLoader().getResource("templates/2.png"); |
|
|
|
|
|
|
@ -99,7 +101,7 @@ public class ImageRotator { |
|
|
|
private static String convertToBase64(BufferedImage image) { |
|
|
|
try { |
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
|
|
|
ImageIO.write(image, "jpeg", outputStream); |
|
|
|
ImageIO.write(image, "PNG", outputStream); |
|
|
|
byte[] imageBytes = outputStream.toByteArray(); |
|
|
|
return Base64.getEncoder().encodeToString(imageBytes); |
|
|
|
} catch (IOException e) { |
|
|
@ -112,7 +114,7 @@ public class ImageRotator { |
|
|
|
public static void main(String[] args) { |
|
|
|
String sourceImagePath = "C:\\Users\\Administrator\\Desktop\\1.png"; // 源图片路径
|
|
|
|
String targetImagePath = "C:\\Users\\Administrator\\Desktop\\2.png"; // 目标图片路径
|
|
|
|
double angle = 90; // 旋转角度
|
|
|
|
double angle = 45.0; // 旋转角度
|
|
|
|
|
|
|
|
String base64Result = rotateAndOverlayImage(sourceImagePath, targetImagePath, angle); |
|
|
|
if (base64Result != null) { |
|
|
|