import android.util.Base64;
导包要用上面标红的,不要使用
import java.util.Base64;
//把bitmap转换成Base64字符串
public static String bitmapToString(Bitmap bitmap) {
String string = null;
ByteArrayOutputStream btString = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, btString);
byte[] bytes = btString.toByteArray();
string = Base64.encodeToString(bytes,Base64.URL_SAFE);
return string;
}
//把Base64字符串转换成bitmap
public static Bitmap base64ToBitmap(String base64String) {
byte[] decode = Base64.decode(base64String.toString().trim(), Base64.URL_SAFE);
Bitmap bitmap = BitmapFactory.decodeByteArray(decode, 0, decode.length);
return bitmap;
}
说明:
string = Base64.encodeToString(bytes,Base64.URL_SAFE);这个标志要用URL_SAFE,不然在转为bitmap时会出错。
然后获取图片的bitmap
可以看
https://blog.csdn.net/ljx1400052550/article/details/79575031