android - Base64图像未显示在android imageview中
问题描述
我试图在图像视图中显示 base64 图像,但它不显示。我正在解码和设置图像视图的图像位图。我正在动态添加图像视图。问题是因为我动态添加图像吗?下面是代码片段:
LayoutInflater inflaterDocuments = (LayoutInflater)GetSystemService(Context.LayoutInflaterService);
View inflatedHeaderLayout = inflaterDocuments.Inflate(Resource.Layout.imageListItem, null, false);
ImageView imageView = inflatedHeaderLayout.FindViewById<ImageView>(Resource.Id.imageView);
byte[] decodedString = Base64.Decode(base64String, Base64Flags.Default);
Bitmap bitMap = BitmapFactory.DecodeByteArray(decodedString, 0, decodedString.Length);
imageView.SetImageBitmap(bitMap);
imageView.Invalidate();
_imageLayout.AddView(inflatedHeaderLayout);
编辑
Base64 字符串文件Base64.txt
解决方案
这是获取base64的方法
public static String getBase64String(Bitmap image) {
String encodeString = null;
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
encodeString = Base64.encodeToString(byteArray, Base64.DEFAULT);
} catch (Exception e) {
e.printStackTrace();
}
return encodeString;
}
滑行用于显示图像
String photoId = base64;
Glide.with(getApplicationContext())
.load(photoId)
.apply(RequestOptions.circleCropTransform())
.into(employeeImage);
推荐阅读
- python - 如何重命名熊猫中的日期列?
- powershell - 在构建任务中使用 $(System.AccessToken) 运行 Invoke-RestMethod 时出错
- reactjs - 是的,react-hook-form:如何在表单中创建有条件的必填字段?
- node.js - Nodemailer not working only when i use .env
- elasticsearch - 从文档中提取唯一术语
- python - 如何防止使用 pysimplegui 创建的窗口无响应?
- d3.js - Why aren't my axes aligned with the viewbox in d3?
- javascript - 菜单打开时隐藏 iOS/android 状态/工具栏
- java - 在 GUI 中打印 ActionListener 的结果
- git - Git - 错误的文件夹结构