Scenes
What is implemented in this project is the function of obtaining the graphic verification code, and Android has its own conversion class
import android.util.Base64;
accomplish
public static Bitmap stringToBitmap(String string) {
Bitmap bitmap = null;
try {
byte[] bitmapArray = Base64.decode(string.split(",")[1], Base64.DEFAULT);
bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
Interface (this interface is for our company to obtain the graphic verification code interface, here you can add your own company's method)
Call this interface method in the click event of the graphic ImageView
BaseJsonBean baseJson = GsonUtils.fromJson(resultJson, BaseJsonBean.class);
int code = (Integer) baseJson.getCode();
if (code == 1) {
if ("GraphVerify".equals(requestTag)) {
Type type = new TypeToken<BaseJsonBean<BaseImageBean>>(){}.getType();
BaseJsonBean<BaseImageBean> baseJsonBean = GsonUtils.fromJson(resultJson, type);
String strbase64 = baseJsonBean.getData().getBase64();
baseKey = baseJsonBean.getData().getKey();
Bitmap bitmap = stringToBitmap(strbase64);
btn_graphVerify.setImageBitmap(bitmap);
}
} else {
String msg = (String) baseJson.getMsg();
ToastUtils.showShort(msg);
}
BaseImageBean class
public class BaseImageBean {
String base64;
String key;
String md5;
public String getBase64() {
return base64;
}
public void setBase64(String base64) {
this.base64 = base64;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getMd5() {
return md5;
}
public void setMd5(String md5) {
this.md5 = md5;
}
}