我想在我的Android应用中显示图片。因为我正在调用我的服务,因为图像采用以下格式:
image:[255,216,255,224,0,16,74,70,73,70,0,1,1,0,0,1,0,1,0,0......].
如何在android中显示此图像。
答案 0 :(得分:0)
byte[] b = Base64.decode(previouslyEncodedImage, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
img.setImageBitmap(bitmap);
答案 1 :(得分:0)
使用以下代码
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(bmp);
这里是bytearray,你从服务器得到什么
答案 2 :(得分:0)
要通知您这称为图像的字节数组,您必须使用Bitmap
类的decodeByteArray
方法将该数组解码为BitmapFactory
,例如,
select(battles,attacker_outcome,attacker_king)
attacker_outcome attacker_king
1 win Joffrey/Tommen Baratheon
2 win Joffrey/Tommen Baratheon
3 win Joffrey/Tommen Baratheon
4 loss Robb Stark
5 win Robb Stark
6 win Robb Stark
7 win Joffrey/Tommen Baratheon
8 win Balon/Euron Greyjoy
9 win Balon/Euron Greyjoy
10 win Balon/Euron Greyjoy
11 win Robb Stark
12 win Balon/Euron Greyjoy
13 win Balon/Euron Greyjoy
14 win Joffrey/Tommen Baratheon
15 win Robb Stark
16 win Stannis Baratheon
17 loss Joffrey/Tommen Baratheon
18 win Robb Stark
19 win Robb Stark
20 loss Stannis Baratheon
21 win Robb Stark
22 loss Robb Stark
23 win
24 win Joffrey/Tommen Baratheon
25 win Joffrey/Tommen Baratheon
26 win Joffrey/Tommen Baratheon
27 win Robb Stark
28 loss Stannis Baratheon
29 win Joffrey/Tommen Baratheon
30 win
31 win Stannis Baratheon
32 win Balon/Euron Greyjoy
33 win Balon/Euron Greyjoy
34 win Joffrey/Tommen Baratheon
35 win Joffrey/Tommen Baratheon
36 win Joffrey/Tommen Baratheon
37 win Joffrey/Tommen Baratheon
38 Stannis Baratheon
答案 3 :(得分:0)
试试这个为我工作
'hanger-cloth.jpg'
解释步骤:
String myString = "[255,216,255....]";
try {
JSONArray arr = new JSONArray(myString);
byte[] myArray = new byte[myString.length()];
for (int i = 0; i < arr.length(); i++) {
myArray[i] = (byte) arr.getInt(i);
}
Bitmap bmp = BitmapFactory.decodeByteArray(myArray, 0, myArray.length);
ImageView image = (ImageView) findViewById(R.id.myImageView);
image.setImageBitmap(bmp);
} catch (JSONException e) {
e.printStackTrace();
}