永发信息网

android 存在数据库中的动态图片,如何读取出来,显示在ImageView中

答案:3  悬赏:0  手机版
解决时间 2021-12-31 16:02
  • 提问者网友:难遇难求
  • 2021-12-31 07:19
android 存在数据库中的动态图片,如何读取出来,显示在ImageView中
最佳答案
  • 五星知识达人网友:怙棘
  • 2021-12-31 07:25
实现的功能为从服务器获取图片数据,在布局页面上显示。由于图片的个数是不确定的,因此采用在布局页面中定义多个ImageView来显示图片是不合理的。
(一)首先定义布局

android:id="@+id/id_layout_movie"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
(二)加载图片显示时获取到布局文件
RelativeLayout rl_Movie = (RelativeLayout) findViewById(R.id.id_layout_movie);
(三)依次循环服务器获取的图片数据,一张一张设置图片显示的位置
//newWidth为图片显示的宽度,newHeight为图片显示的高度
RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams( newWidth, newHeight);
设置lp1.leftMargin和lp1.topMargin的值
(四)最后设置rl_Movie.addView(iv, lp1)将图片加入布局文件中
全部回答
  • 1楼网友:野味小生
  • 2021-12-31 08:42
给你个参考,我这边数据库存的是base64的不知道是不是和你存的一样 //首先需要 把Base64转换成Bitmap public Bitmap getBitmap(String iconBase64) { byte[] bitmapArray; bitmapArray = Base64.decode(iconBase64); return BitmapFactory .decodeByteArray(bitmapArray, 0, bitmapArray.length); } ImageView imgPhoto=(ImageView) findViewById(R.id.image_photo); Bitmap bi = getBitmap(photoCode);//这里调用的时候传的是查出来的图片的base64字符串编码 imgPhoto.setImageBitmap(bi);
  • 2楼网友:夜余生
  • 2021-12-31 08:25
通过流的形式就可以了。通过路径得到文件流,然后使用bitmapfactory.decodestream 方法 得到一个bitmap 然偶通过imageview.setimagebitmap()就ok了
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯