首页 > 其他分享 >Android/ImageButton如何显示二进制字符流的图片

Android/ImageButton如何显示二进制字符流的图片

时间:2023-09-15 14:12:24浏览次数:40  
标签:ImageButton bitmapArray bitmap 二进制 Android Bitmap 图片

今天做获取用户接口信息,结构如下所示(UserIcon的值只是部分,不可用),有返回用户图片的信息(二进制),需要在页面显示,这里做下笔记

{
    "UserCode":"admin",
    "UserName":"管理员",
    "UserIcon":"iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAUCklEQVR4nO2da5RdZX3Gf88+l8kkk2SSyd0"
}

1)直接在控件设置图片来源

 <ImageButton
                        android:id="@+id/img_in_pack_user_icon"
                        android:layout_width="80dp"
                        android:layout_height="120dp"
                        android:background="@color/colorWhite"
                        android:src="@drawable/icon_un_login128"
                        android:scaleType="fitCenter"
                        />

2)通过后台动态设置图片来源(安卓图片资源)

 ImageButton imgUserIcon = findViewById(R.id.img_in_pack_user_icon);
 imgUserIcon.setImageResource(R.drawable.icon_male_doctor128);

3)通过后台动态设置图片来源(二进制字符流转成图片)

3.1)将二进制字符流转成Bitmap方法

   public static Bitmap convertStringToIcon(String outPut){
        Bitmap bitmap = null;
        try{
            byte[] bitmapArray;
            bitmapArray = android.util.Base64.decode(outPut, android.util.Base64.DEFAULT);
            bitmap = BitmapFactory.decodeByteArray(bitmapArray,0,bitmapArray.length);

        }catch (Exception ex){
            ex.printStackTrace();
        }
        return bitmap;
    }

3.2)调用转换方法并设置图片

  String imgStream = "iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAUCklEQVR4nO2da5RdZX3Gf88+l8kkk2SSyd0QLlEwUDEJKBDABFotWhBB2w8VoZQ54VMXa1VczpilH3TFM12FrsXqJzJDFbVfasW6pF1Yl5jUGC41CYqAWCKYBCYkmdwvM+eyn344MyGTzOScObd9JjnPlydnsvf+v+9+n//zvnvvd79bnEfoSWVbDQuBhYIFofMXSbGLQEvA84E5kjpsz5Uk2x7N7JUYsL0f9C7yTju/S8R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dRhO1mlDB+SNGB7QNIe269g/9LwK0n7wYPdvY2d6eNh0gpgLPSksq0WCzELgYUmv1iKXYS1BJgvMQfoAOaNc4i9FD6lux/0Lninnd8lxXZT+LZSP6i/uzd+sj41qj3+HzHJ1TdUHPJQAAAAAElFTkSuQmCC";
  Bitmap bitmap = ToolHelper.convertStringToIcon(imgStream);
  imgUserIcon.setImageBitmap(bitmap);

参考地址:https://blog.csdn.net/cf8833/article/details/52371491

 

标签:ImageButton,bitmapArray,bitmap,二进制,Android,Bitmap,图片
From: https://www.cnblogs.com/xielong/p/17704884.html

相关文章

  • 我的 Android 学习之路,一位 5 年中大厂的 Android 老哥跟你聊聊
    本文首发我的微信公众号:程序员徐公光阴似箭,日月如梭,时间真的过得飞快。加上实习,从事Android开发,差不多有5年了,在这里,我分享一下我的经验,在Android的学习路上,我是站在巨人的肩膀上成长起来的。大概分为三个部分一、Android职业规划二、Android学习路线三、如何进入大厂An......
  • Android平台GB28181设备接入侧如何实现按需打开视音频采集传输
    GB/T28181规范GB/T28181是中国国家标准,全称为《安全防范视频监控联网系统信息传输、交换、控制技术要求》,该标准规定了城市安全防范监控系统中视频监控联网系统的一般要求和架构,以及信息传输、交换、控制的技术要求。它主要应用于安防领域,为各种视频监控系统提供了一致的接口规范,使......
  • 过去3个月各种Android面试
    在过去的3个月里,笔者历经了各种面试的考验。这场考验,就像是在造火箭,复杂而艰辛。尽管如此,笔者凭借自己的实力和努力,最终拿下了百度、腾讯和京东的录用通知。经过深思熟虑,笔者可能会选择京东,这也许让你感到有些意外。腾讯无疑是一个诱人的选择,它提供的薪资和福利待遇都相当可观。笔......
  • android中的VERSION和VERSION_CODES和compileSdkVersion, minSdkVersion 和 targetSdk
    一背景经常会有代码中用到  Build.VERSION.SDK_INT<Build.VERSION_CODES.O,这是指什么意思。在app项目中,经常会看到android{compileSdkVersion30buildToolsVersion"30.0.3"defaultConfig{applicationId"com.yl.qrcode"minSdkVersio......
  • Android studio 修改APK打包生成名称
    在app的build.gradle的android{}添加一下代码android.applicationVariants.all{variant->variant.outputs.all{defcreateTime=newDate().format("YYYYMMdd",TimeZone.getTimeZone("GMT+08:00"))//在这里修改apk文件名......
  • Flutter插件flutter_boost 在android模块中的报红问题解决.
    1,在开发Flutter插件时,打开插件的android项目,准备编写native端的代码时,发现各种报红,代码无法跳转,体验十分不好。就像我下面的截图一样:导入了FlutterBoostflutterBoost源码爆红。但是运行正常。。这说明本身是没有问题的。。分明是没有错误的类都存在。但是就是爆红。。。。可......
  • Android 9 WiFi连接过程
    我们从setting 入口开始分析该过程;1.setting界面 packages\apps\Settings\src\com\android\settings\wifi\WifiSettings.java 创建Dialog2@OverridepublicDialogonCreateDialog(intdialogId){switch(dialogId){caseWIFI_DIALOG_ID:......
  • 独家珍藏的Android面试突击宝典,轻松应对95%秋招面试题
    前言最近发现了很多同学出现的一个问题,简历已读不回,没有面试机会等等问题,觉得互联网不行了,Android不行了,甚至有人说自己这辈子最后悔的事情就是进入it这个行业。我每次看到这样的反馈或者这样的说法的时候,心里总不是滋味,我承认大家现在反馈的问题在一定程度上确实是客观存在的情况,......
  • Android广播接收器详解
    1.Android广播接收器简介在Android中,BroadcastReceiver(广播接收器)是一种组件,用于监听系统广播或应用程序内自定义广播,并在广播发生时接收并处理这些广播。广播接收器可以用于实现组件之间的通信,无论是在同一个应用程序内还是在不同应用程序之间。广播接收器有两个主要部分:注册广......
  • Android软键盘弹出关闭监听
    https://juejin.cn/post/6844903489051557902?from=singlemessage&isappinstalled=0#commentpackagecom.xiucai.common.manager;importandroid.graphics.Rect;importandroid.util.Log;importandroid.view.View;importandroid.view.ViewTreeObserver;import......