public class BitmapStringUtils {
/**
* 将bitmap转换成为Base64
* @param bitmap
* @return
*/
public static String
bitmaptoString(Bitmap bitmap) {
String string =
null;
ByteArrayOutputStream bStream =
new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG,
10, bStream);
byte[] bytes = bStream.toByteArray();
string = Base64.encodeToString(bytes, Base64.DEFAULT);
return string;
}
/**
* 将Base64转换成为Bitmap
* @param string
* @return
*/
public static Bitmap
stringtoBitmap(String string){
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;
}
}
12345678910111213141516171819202122232425262728293031323334
使用方法
Bitmap headBitmap = data
.getParcelableExtra(
"data")
RequestBody requestBody = new RequestBody(UserInfoActivity
.this)
requestBody
.setHeadImg(BitmapStringUtils
.bitmaptoString(headBitmap))
RequestUtils
.createApi()
.uploadHeadImg(requestBody)
.subscribeOn(Schedulers
.io())
.observeOn(AndroidSchedulers
.mainThread())
.subscribe(new CommonsSubscriber<Response>() {
@Override
protected void onSuccess(Response response) {
Toast
.makeText(UserInfoActivity
.this, response
.getReturnInfo(), Toast
.LENGTH_SHORT)
.show()
getUser()
}
})
转载请注明原文地址: https://ju.6miu.com/read-666475.html