如何在android中显示图像

时间:2016-07-18 06:52:03

标签: android wcf

我想在我的Android应用中显示图片。因为我正在调用我的服务,因为图像采用以下格式:

 image:[255,216,255,224,0,16,74,70,73,70,0,1,1,0,0,1,0,1,0,0......].

如何在android中显示此图像。

4 个答案:

答案 0 :(得分:0)

你能解释得更详细吗?您的图像是否为64格式。如果是这样,您必须解码图像并在imageview中显示它。

 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();
}