图像转字符串
public static String imageToString(String filePath) {
try (FileInputStream imageInFile = new FileInputStream(filePath)) {
byte[] imageBytes = new byte[(int) new File(filePath).length()];
imageInFile.read(imageBytes);
String encodedString = Base64.getEncoder().encodeToString(imageBytes);
return "data:image/png;base64," + encodedString; // Assuming the image is PNG, adjust if necessary
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
// 解码Base64字符串标签:String,filePath,Base64,imageBytes,图像,字符串,new,byte From: https://www.cnblogs.com/hbro/p/18541272
byte[] imageBytes = Base64.getDecoder().decode(animeUrl);
ImageIcon animeIcon = new ImageIcon(imageBytes);
animefyLabel.setIcon(animeIcon);
System.out.println(response.body().string());