Springboot’s picture under static resources Turn to base64

2023-01-30  

/** 
      * 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); 
     }

source

Random Posts

异常记录 严重 org.apache.catalina.core.StandardContext.listenerStart Error configuring application listene星尘

MyCat can’t start because of memory size

Machine Learning Algorithm artificial neural network

mybatis ﹤! [Cdata []]> Use

POJ 1146 ID CODES (generated arrangement) TCGOGOGO