The jar package is Commons-codec.jar.
Pnuts
//base64 is decoded into a picture
Function gldBase64ToImage(imgStr,imgFilePath) {
// Base64 decoding of byte array strings and generating images
If ("".equals(imgStr) || imgStr == null) // Image data is empty
Return false
//When transcoding, it may have a prefix format, so you need to split and take a valid string.
imgArr = imgStr.split(",")
If(imgArr.length == 1){
imgStr = imgArr[0]
}else{
imgStr = imgArr[1]
}
imgByte = class org.apache.commons.codec.binary.Base64::decodeBase64(imgStr)
// Base64 decoding
For (i = 0; i < imgByte.length; ++i) {
If (imgByte[i] < 0) {// Adjust the exception data
imgByte[i] += 256;
}
}
Out = class java.io.FileOutputStream(imgFilePath)
Out.write(imgByte)
Out.flush()
Out.close()
}
Java
/**
* Base64 decoding of byte array strings and generating images
* @param imgStr image data
* @param imgFilePath save image full path address
* @return
*/
Public static boolean generateImage(String imgStr,String imgFilePath){
//
If ( "".equals(imgStr) || imgStr == null) //The image data is empty
Return false;
Try
{
//Base64 decoding
Byte[] b = Base64.decodeBase64(imgStr);
For(int i=0;i<b.length;++i)
{
If(b[i]<0)
{//Adjust exception data
b[i]+=256;
}
}
/ / Generate jpeg picture
OutputStream out = new FileOutputStream(imgFilePath);
Out.write(b);
Out.flush();
Out.close();
Return true;
}
Catch (Exception e)
{
Return false;
}
}
}
iOS Development UI chapter-Creating a navigation controller and the life cycle of a controller using storyboard