/**
* Local pictures converted to base64 string
* @param ImageName Picture Name
* @Reture Picture Base64
* @Author Byr
* @datetime 2019-03-07
*/
Public Static String ImageTobase64ByLocal (String ImageName) Throws IOEXception {{
InputStream in = NULL;
byte [] data = null;
// Read the picture byte array
try {
// Get the picture path
Resource resource = New classpathResource ("/Static/ImageSeal/"+ImageName+". Png");
File file = resource.getfile ();
in = new fileinputstream (file.getpath ());
data = new byte [in.available ()];
in.read (data);
in.close ();
} Catch (IOEXception E) {{
e.printstacktrace ();
}
// Byte array base64 encoding
Base64Encoder encoder = New base64enCoder ();
// Return the base64 encoded byte array component
Return encoder.encode (data);
}
Springboot’s picture under static resources Turn to base64
2023-01-30