Android : SkiImageDecoder Factory : returned null when trying to decode a byte array

on Monday, August 11, 2014


I have written a rest webservice from which the image is fetched and then i converted it into a byte array. The image is retrieved and when i check the length of the byte array it says 15.


How can i decode this image and view it on my android app.


The code i used is as follows


protected void onPostExecute(ArrayList res) { // TODO Auto-generated method stub



// System.out.println("Helloooooo" + res.get(0).getimg_storage());
System.out.println("HEllooooooooooo" + res);

for (int i = 0; i < res.size(); i++) {
data.add(res.get(i).getimg_storage());
}

System.out.println("datoooo" + data);
//data = res.get(0).getimg_storage();


int size = data.size();

ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(baos);
try{
for (String element : data) {
out.writeUTF(element);
}
}

catch(Exception e)
{
System.out.println("elemant error");


}

byte[] bytes = baos.toByteArray();

System.out.println("Aiyooooooowwwwwwwwwwww" + bytes);
System.out.println("lennnn" + bytes.length);

Bitmap bitmap = BitmapFactory.decodeByteArray(bytes , 0, bytes.length);
}


}

0 comments:

Post a Comment