我是 android 新手。图像存储在服务器中Base64格式。那么我怎样才能得到它server to 我的项目并使用 Json 对象设置为我的 ImageView。
请帮我
任何帮助将不胜感激
尝试这个:
首先将 Url 转换为 byte[]:
byte[] bitmapdata = getByteArrayImage(url);
Method:
private byte[] getByteArrayImage(String url){
try {
URL imageUrl = new URL(url);
URLConnection ucon = imageUrl.openConnection();
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(500);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
return baf.toByteArray();
} catch (Exception e) {
Log.d("ImageManager", "Error: " + e.toString());
}
return null;
}
现在将 byte[] 转换为位图
Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapdata , 0, bitmapdata .length);
并将位图设置为 ImageView:
img= (ImageView) findViewById(R.id.imgView);
img.setImageBitmap(bitmap );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)