3
In the html(jsp) of registration I have a field that the user registers his photo with the tag img with the following result.
<img src="data:image/png;Base64,/9/0kmkdmkewnsjdncijndcjdxncdjcdscjnccc/ccnkjdncnsjnidckcmokcmoskcmkosmcokmdscjncjncjcsnckdjncojnscjncdjnckmkdmcokscmksmdckcmsokcmnjncjemncmokkjcmdjsdccmslckjplqmkmokswkmxokamlamklmockmclmdkcmlodkcmokcmkmcokmsomcksmcsfhhgfrfcghjkuytredfhjolkjhsSWswjshuhuwhuhyhuimcoskcmkmsckmkmkcmc"
/>
I’m converting the section after Base64, in a byte[] with sun.misc.Base64decoder, as below:
import Decoder.BASE64Decoder;
import Decoder.BASE64Encoder;
/**
* @author Tiago Ferezin
*
* para o tratamento da imagem
*
*/
public class Imagem {
public static byte[] convertBase64StringToByteArray(String imagem){
byte[] retorno = null;
try {
BASE64Decoder decoder = new BASE64Decoder();
retorno = decoder.decodeBuffer(imagem);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return retorno;
}
public static String convertByteArrayToBase64String(byte[] imagem){
String retorno="";
try {
BASE64Encoder encoder = new BASE64Encoder();
retorno = encoder.encode(imagem);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return retorno;
}
}
And write the generated byte[] to the bank.
First wanted to know how before recording in the bank, take the image type(png,ttf,jpg,psd) and convert to JPEG, and then generate an array of it and save to the database?
Second, I would like to know how to convert this byte[] saved in the database to a String data:image/jpeg;Base64,{byte[]} to tag img on another JSP page?