main
HuangHai 2 months ago
parent b3ea4acf1b
commit 3ab072d21a

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 KiB

@ -143,8 +143,7 @@ public class JmCommon {
String signature = HexFormat.of().formatHex(hmacSHA256(signKey, signString));
// 构建URL并创建HTTP连接
URI uri = new URI(schema, "//" + host + path, "?" + querySB.toString());
URL url = uri.toURL();
URL url = new URL(schema + "://" + host + path + "?" + querySB);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod(method);

@ -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);
}
}

Loading…
Cancel
Save