|
@@ -0,0 +1,247 @@
|
|
|
|
+//package com.txz.operating.controller;
|
|
|
|
+//
|
|
|
|
+//import javax.imageio.ImageIO;
|
|
|
|
+//import java.awt.*;
|
|
|
|
+//import java.awt.image.BufferedImage;
|
|
|
|
+//import java.io.File;
|
|
|
|
+//import java.io.IOException;
|
|
|
|
+//import java.util.Random;
|
|
|
|
+//import java.util.ArrayList;
|
|
|
|
+//import java.util.List;
|
|
|
|
+//import java.util.Collections;
|
|
|
|
+//
|
|
|
|
+//public class DiverseMacaronAvatarGenerator {
|
|
|
|
+//
|
|
|
|
+// // 输出目录
|
|
|
|
+// private static final String OUTPUT_DIR = "diverse_macaron_avatars";
|
|
|
|
+// // 头像尺寸
|
|
|
|
+// private static final int AVATAR_SIZE = 200;
|
|
|
|
+// // 每个字母生成的头像数量
|
|
|
|
+// private static final int AVATARS_PER_LETTER = 10;
|
|
|
|
+// // 每次运行使用的颜色数量
|
|
|
|
+// private static final int COLORS_TO_USE = 10;
|
|
|
|
+//
|
|
|
|
+// // 差异更大的马卡龙色系颜色池 (RGB值) - 50种颜色
|
|
|
|
+// private static final Color[] MACARON_COLOR_POOL = {
|
|
|
|
+// // 粉色系(不同深浅)
|
|
|
|
+// new Color(255, 220, 230), // 浅粉红
|
|
|
|
+// new Color(250, 190, 210), // 中粉红
|
|
|
|
+// new Color(245, 170, 195), // 深粉红
|
|
|
|
+// new Color(250, 210, 225), // 淡粉
|
|
|
|
+//
|
|
|
|
+// // 紫色系
|
|
|
|
+// new Color(230, 210, 250), // 浅紫
|
|
|
|
+// new Color(210, 180, 240), // 中紫
|
|
|
|
+// new Color(190, 150, 230), // 深紫
|
|
|
|
+// new Color(240, 220, 255), // 淡紫
|
|
|
|
+//
|
|
|
|
+// // 蓝色系
|
|
|
|
+// new Color(200, 220, 250), // 浅蓝
|
|
|
|
+// new Color(170, 200, 240), // 中蓝
|
|
|
|
+// new Color(140, 180, 230), // 深蓝
|
|
|
|
+// new Color(220, 235, 255), // 淡蓝
|
|
|
|
+//
|
|
|
|
+// // 绿色系
|
|
|
|
+// new Color(200, 240, 220), // 浅绿
|
|
|
|
+// new Color(160, 230, 190), // 中绿
|
|
|
|
+// new Color(120, 210, 160), // 深绿
|
|
|
|
+// new Color(220, 250, 230), // 淡绿
|
|
|
|
+//
|
|
|
|
+// // 黄色系
|
|
|
|
+// new Color(250, 240, 200), // 浅黄
|
|
|
|
+// new Color(240, 220, 150), // 中黄
|
|
|
|
+// new Color(230, 200, 100), // 深黄
|
|
|
|
+// new Color(255, 250, 220), // 淡黄
|
|
|
|
+//
|
|
|
|
+// // 橙色系
|
|
|
|
+// new Color(250, 220, 180), // 浅橙
|
|
|
|
+// new Color(245, 200, 140), // 中橙
|
|
|
|
+// new Color(240, 180, 100), // 深橙
|
|
|
|
+// new Color(255, 230, 200), // 淡橙
|
|
|
|
+//
|
|
|
|
+// // 红色系(马卡龙风格)
|
|
|
|
+// new Color(250, 200, 200), // 浅红
|
|
|
|
+// new Color(240, 170, 170), // 中红
|
|
|
|
+// new Color(230, 140, 140), // 深红
|
|
|
|
+//
|
|
|
|
+// // 青蓝色系
|
|
|
|
+// new Color(200, 240, 240), // 浅青
|
|
|
|
+// new Color(160, 230, 230), // 中青
|
|
|
|
+// new Color(120, 210, 210), // 深青
|
|
|
|
+//
|
|
|
|
+// // 棕色系(马卡龙风格)
|
|
|
|
+// new Color(240, 210, 180), // 浅棕
|
|
|
|
+// new Color(230, 190, 150), // 中棕
|
|
|
|
+//
|
|
|
|
+// // 薄荷色系
|
|
|
|
+// new Color(200, 250, 230), // 浅薄荷
|
|
|
|
+// new Color(160, 240, 210), // 中薄荷
|
|
|
|
+//
|
|
|
|
+// // 珊瑚色系
|
|
|
|
+// new Color(250, 210, 190), // 浅珊瑚
|
|
|
|
+// new Color(245, 190, 160), // 中珊瑚
|
|
|
|
+//
|
|
|
|
+// // 薰衣草色系
|
|
|
|
+// new Color(220, 200, 240), // 浅薰衣草
|
|
|
|
+// new Color(200, 170, 230), // 中薰衣草
|
|
|
|
+//
|
|
|
|
+// // 橄榄色系(浅)
|
|
|
|
+// new Color(220, 230, 200), // 浅橄榄
|
|
|
|
+// new Color(200, 220, 170), // 中橄榄
|
|
|
|
+//
|
|
|
|
+// // 莓红色系
|
|
|
|
+// new Color(240, 190, 220), // 浅莓红
|
|
|
|
+// new Color(230, 160, 200), // 中莓红
|
|
|
|
+//
|
|
|
|
+// // 天蓝色系
|
|
|
|
+// new Color(190, 220, 240), // 浅天蓝
|
|
|
|
+// new Color(150, 200, 230), // 中天蓝
|
|
|
|
+//
|
|
|
|
+// // 石灰色系(浅)
|
|
|
|
+// new Color(230, 230, 235), // 浅灰
|
|
|
|
+// new Color(210, 210, 220), // 中灰
|
|
|
|
+//
|
|
|
|
+// // 香槟色系
|
|
|
|
+// new Color(250, 240, 225), // 浅香槟
|
|
|
|
+// new Color(240, 225, 200), // 中香槟
|
|
|
|
+//
|
|
|
|
+// // 木瓜色系
|
|
|
|
+// new Color(250, 225, 200), // 浅木瓜
|
|
|
|
+// new Color(245, 210, 170) // 中木瓜
|
|
|
|
+// };
|
|
|
|
+//
|
|
|
|
+// // 本次运行实际使用的10种颜色
|
|
|
|
+// private static Color[] selectedColors;
|
|
|
|
+//
|
|
|
|
+// public static void main(String[] args) {
|
|
|
|
+// // 从50种颜色中随机选择10种颜色
|
|
|
|
+// selectRandomColors();
|
|
|
|
+//
|
|
|
|
+// // 创建输出目录
|
|
|
|
+// createOutputDirectory();
|
|
|
|
+//
|
|
|
|
+// // 为每个字母生成指定数量的头像
|
|
|
|
+// for (char c = 'A'; c <= 'Z'; c++) {
|
|
|
|
+// generateAvatarsForLetter(c);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// System.out.println("所有头像生成完成!保存路径:" + new File(OUTPUT_DIR).getAbsolutePath());
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 从颜色池中随机选择指定数量的颜色
|
|
|
|
+// private static void selectRandomColors() {
|
|
|
|
+// List<Color> colorList = new ArrayList<>();
|
|
|
|
+// for (Color color : MACARON_COLOR_POOL) {
|
|
|
|
+// colorList.add(color);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 打乱颜色顺序
|
|
|
|
+// Collections.shuffle(colorList);
|
|
|
|
+//
|
|
|
|
+// // 选择前10种颜色
|
|
|
|
+// selectedColors = new Color[COLORS_TO_USE];
|
|
|
|
+// for (int i = 0; i < COLORS_TO_USE; i++) {
|
|
|
|
+// selectedColors[i] = colorList.get(i);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 为单个字母生成指定数量的头像
|
|
|
|
+// private static void generateAvatarsForLetter(char letter) {
|
|
|
|
+// // 为每个字母创建单独的子目录
|
|
|
|
+// String letterDir = OUTPUT_DIR + File.separator + letter;
|
|
|
|
+// File dir = new File(letterDir);
|
|
|
|
+// if (!dir.exists()) {
|
|
|
|
+// dir.mkdirs();
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 生成指定数量的头像
|
|
|
|
+// for (int i = 1; i <= AVATARS_PER_LETTER; i++) {
|
|
|
|
+// try {
|
|
|
|
+// // 生成头像
|
|
|
|
+// BufferedImage avatar = generateAvatar(letter, AVATAR_SIZE);
|
|
|
|
+//
|
|
|
|
+// // 保存头像
|
|
|
|
+// String fileName = letter + "_" + i + ".png";
|
|
|
|
+// String filePath = letterDir + File.separator + fileName;
|
|
|
|
+// ImageIO.write(avatar, "png", new File(filePath));
|
|
|
|
+//
|
|
|
|
+// System.out.printf("生成头像: %s%n", filePath);
|
|
|
|
+// } catch (IOException e) {
|
|
|
|
+// System.err.printf("生成字母 %c 的第 %d 个头像时出错: %s%n", letter, i, e.getMessage());
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 生成单个字母头像
|
|
|
|
+// private static BufferedImage generateAvatar(char letter, int size) {
|
|
|
|
+// // 创建图像
|
|
|
|
+// BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);
|
|
|
|
+// Graphics2D g = image.createGraphics();
|
|
|
|
+//
|
|
|
|
+// try {
|
|
|
|
+// // 设置抗锯齿,使图像更平滑
|
|
|
|
+// g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
|
+// g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
|
|
+//
|
|
|
|
+// // 从选中的10种颜色中随机选择背景颜色
|
|
|
|
+// Color bgColor = getRandomSelectedColor();
|
|
|
|
+// g.setColor(bgColor);
|
|
|
|
+//
|
|
|
|
+// // 绘制完整的圆角矩形背景
|
|
|
|
+// int radius = size / 8;
|
|
|
|
+// g.fillRoundRect(0, 0, size, size, radius, radius);
|
|
|
|
+//
|
|
|
|
+// // 根据背景色亮度动态选择文字颜色,确保更好的对比度
|
|
|
|
+// Color textColor = getContrastColor(bgColor);
|
|
|
|
+// g.setColor(textColor);
|
|
|
|
+//
|
|
|
|
+// // 设置字体,增加多样性
|
|
|
|
+// String[] fonts = {"Arial", "Helvetica", "Verdana", "Georgia", "Times New Roman"};
|
|
|
|
+// String fontName = fonts[new Random().nextInt(fonts.length)];
|
|
|
|
+// Font font = new Font(fontName, Font.BOLD, size / 2);
|
|
|
|
+// g.setFont(font);
|
|
|
|
+//
|
|
|
|
+// // 计算文本位置,使其居中显示
|
|
|
|
+// FontMetrics metrics = g.getFontMetrics(font);
|
|
|
|
+// int textWidth = metrics.charWidth(letter);
|
|
|
|
+// int textAscent = metrics.getAscent();
|
|
|
|
+// int x = (size - textWidth) / 2;
|
|
|
|
+// int y = (size - metrics.getHeight()) / 2 + textAscent;
|
|
|
|
+//
|
|
|
|
+// // 绘制字母
|
|
|
|
+// g.drawString(String.valueOf(letter), x, y);
|
|
|
|
+//
|
|
|
|
+// return image;
|
|
|
|
+// } finally {
|
|
|
|
+// g.dispose();
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 从选中的10种颜色中随机选择一种
|
|
|
|
+// private static Color getRandomSelectedColor() {
|
|
|
|
+// Random random = new Random();
|
|
|
|
+// int index = random.nextInt(selectedColors.length);
|
|
|
|
+// return selectedColors[index];
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 根据背景色计算对比度最高的文字颜色
|
|
|
|
+// private static Color getContrastColor(Color bgColor) {
|
|
|
|
+// // 计算颜色亮度
|
|
|
|
+// double luminance = (0.299 * bgColor.getRed() + 0.587 * bgColor.getGreen() + 0.114 * bgColor.getBlue()) / 255;
|
|
|
|
+//
|
|
|
|
+// // 对于较暗的背景使用白色文字,较亮的背景使用深灰色文字
|
|
|
|
+// return luminance < 0.6 ? Color.WHITE : new Color(50, 50, 50);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 创建输出目录
|
|
|
|
+// private static void createOutputDirectory() {
|
|
|
|
+// File dir = new File(OUTPUT_DIR);
|
|
|
|
+// if (!dir.exists()) {
|
|
|
|
+// if (dir.mkdirs()) {
|
|
|
|
+// System.out.println("创建输出目录: " + dir.getAbsolutePath());
|
|
|
|
+// } else {
|
|
|
|
+// throw new RuntimeException("无法创建输出目录: " + dir.getAbsolutePath());
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//}
|