//将字符串转换成Bitmap类型
Bitmap bitmap=null;
try {
byte[]bitmapArray;
bitmapArray=Base64.decode(string, Base64.DEFAULT);
bitmap=BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
//将Bitmap转换成字符串
public String bitmaptoString(Bitmap bitmap){
String string=null;
ByteArrayOutputStream bStream=new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG,100,bStream);
byte[]bytes=bStream.toByteArray();
string=Base64.encodeToString(bytes,Base64.DEFAULT);
return string;
}
将数据传递给服务端的时候报错,这时候就得转化一下编码格式,将获取回来的String进行转码,转成UTF-8这样解决了非法字符的问题
String strData = Base64.encodeToString(data, 0, data.length,Base64.DEFAULT);