jakubee 0 Newbie Poster

Hi All,
My problem is: i'm trying to convert byte[] into image. The byte[] comes from JSON and it's in this format:

"4oCwUE5HDQoaCgAAAA1JSERSAAAAfwAAAFAIBgAAADBHwqrDsAAAAAlwSFlzAAAAJwAAACcBKgnigJhPAAAgAElEQVR4xZPCrMK9ecWSZcOZfcOfw7c5w5vCvW/CqXp..." it goes for another 100 lines.

The code where the problem occurs:

DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(PlayersListActivity.URL);
        httpPost.setEntity(new UrlEncodedFormEntity(parameters, "UTF-8"));
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        BufferedHttpEntity bufferedEntity = new BufferedHttpEntity(httpEntity);
        // if this is null the web service returned an empty page
        if(httpEntity == null) // response is empty so exit out
            return null;

        String jsonString = EntityUtils.toString(bufferedEntity);

        // again some simple validation around the returned string
        if(jsonString != null && jsonString.length() != 0) // checking string returned from service to grab id
            JSONArray jsonArray = new JSONArray(jsonString);
            for(int i=0; i< jsonArray.length(); i++)
                HashMap<String, Object> map = new HashMap<String, Object>();

                JSONObject jsonObject = (JSONObject) jsonArray.get(i);
                int id = jsonObject.getInt("id");
                String name = jsonObject.getString("name");
                byte[] images = jsonObject.getString("image").getBytes();

                String base64 = jsonObject.getString("image");
                byte[] decodedString = Base64.decode(base64, Base64.DEFAULT);
                Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
                ImageView image = (ImageView) findViewById(R.id.image);

                map.put("name", name.toString());
                map.put("image", images.toString());

                Log.d("JSON OBJECTS:", jsonObject.toString());
                Log.d("WHATS IN MAP:", map.toString());


And ofcourse error that I'm getting in LogCat:

SkImageDecoder:: Factory returned null.

and it points out on this line:

Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
I have done reseach but nothing really points on what I'm missing. Any ideas??


Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.