用dio get请求网络图片的url,请求的options需要设置一下responseType
Options(responseType: ResponseType.bytes)
方法如下:
static Future<String> netImageToBase64(String imageUrl) async {
Response response = await NetworkManager().get(
imageUrl,
options: Options(responseType: ResponseType.bytes),
);
String base64Str = base64Encode(response.data);
return base64Str;
}
网友评论