|
|
|
@ -27,7 +27,6 @@ public class JmText2Image extends JmCommon {
|
|
|
|
|
req.put("prompt", prompt);
|
|
|
|
|
String responseBody = doRequest("POST", new HashMap<>(), req.toString().getBytes(), action);
|
|
|
|
|
JSONObject jo = JSON.parseObject(responseBody);
|
|
|
|
|
log.info(jo.toString());
|
|
|
|
|
String imgBase64 = jo.getJSONObject("data").getJSONArray("binary_data_base64").getFirst().toString();
|
|
|
|
|
// 对 Base64 字符串进行解码
|
|
|
|
|
Base64.Decoder decoder = Base64.getDecoder();
|
|
|
|
@ -36,7 +35,7 @@ public class JmText2Image extends JmCommon {
|
|
|
|
|
try (OutputStream os = new FileOutputStream(saveImgPath)) { // 使用-with try-resources 自动关闭资源
|
|
|
|
|
os.write(bytes);
|
|
|
|
|
os.flush(); // 刷新缓冲区,确保数据写入文件
|
|
|
|
|
log.info("文件保存成功!");
|
|
|
|
|
log.info("文件保存成功!文件位置:" + saveImgPath);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("文件保存失败!" + e.getMessage());
|
|
|
|
|
}
|
|
|
|
@ -44,8 +43,13 @@ public class JmText2Image extends JmCommon {
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
|
//String prompt = "制作一张vlog视频封面。马卡龙配色,美女旅游照片+色块的拼贴画风格,主文案是“威海旅游vlog”,副文案是“特种兵一日游 被低估的旅游城市”,海报主体是一个穿着短裙、梳双马尾的少女,人物白色描边";
|
|
|
|
|
String prompt="过曝,强对比,夜晚,雪地里,巨大的黄色浴缸,小狗泡澡带墨镜,在喝红酒,胶片摄影,毛刺质感,复古滤镜,夜晚,过度曝光,古早,70年代摄影,复古老照片,闪光灯拍摄,闪光灯效果,过曝,过度曝光,闪光灯过曝,极简,高饱和复古色,70s vintage photography, vintage, retro style";
|
|
|
|
|
String saveImagePath = "d:/Temp/2.jpg";
|
|
|
|
|
String prompt = "过曝,强对比,夜晚,雪地里,巨大的黄色浴缸,小狗泡澡带墨镜,在喝红酒,胶片摄影,毛刺质感,复古滤镜,夜晚,过度曝光,古早,70年代摄影,复古老照片,闪光灯拍摄,闪光灯效果,过曝,过度曝光,闪光灯过曝,极简,高饱和复古色,70s vintage photography, vintage, retro style";
|
|
|
|
|
// 获取项目根目录路径
|
|
|
|
|
String projectRoot = System.getProperty("user.dir")+"/dsAiSupport";
|
|
|
|
|
// 拼接相对路径
|
|
|
|
|
String basePath = projectRoot + "/src/main/java/com/dsideal/aiSupport/Util/JiMeng/Example/";
|
|
|
|
|
String saveImagePath = basePath + "2.jpg";
|
|
|
|
|
log.info("保存图片路径:" + saveImagePath);
|
|
|
|
|
JmText2Image.generateImage(prompt, saveImagePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|