来源于网络,用以备忘

1
2
3
4
5
6
7
8
9
10
//将Bitmap转为String,方便存储
String imgstr=null;
ByteArrayOutputStream outputStream=new ByteArrayOutputStream(); //压缩图片
bm.compress(Bitmap.CompressFormat.PNG,80,outputStream);
byte[] imagbyte=outputStream.toByteArray();
imgstr=Base64.enpreToString(imagbyte, Base64.DEFAULT);

//将String转为Bitmap
byte[] img= Base64.depre(jsonObject.get("musicImage").toString(),Base64.DEFAULT);
Bitmap bm= BitmapFactory.depreByteArray(img,0,img.length);