Please somebody tell me how to create a bitmap out of this?

104 Views Asked by At

Im building an app, which makes it possible to up and download image files. Im receiving an inputstream from a server when i ask for image files. if i call the method just after i uploaded the picture without closing my app first, its possible to decode the stream to a bitmap and everything works fine.

But if i close first, i doesn't work and the content looks different. the string i get looks like "{"Attachment":"/9j/4S5RXhp....."

1

There are 1 best solutions below

0
On BEST ANSWER
            BufferedReader streamReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
            StringBuilder responseStrBuilder = new StringBuilder();

            String inputStr;
            while ((inputStr = streamReader.readLine()) != null)
                responseStrBuilder.append(inputStr);

            JSONObject att = new JSONObject(responseStrBuilder.toString());

            byte[] bytes = Base64.decode(att.getString("Attachment"), Base64.DEFAULT);
            bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);