Sign up ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

Ok i've googled this topic found couple not really examples but ways to accomplish task similar to mine. So long story told short; i am trying to send an image from database with json string through java webservice, i am comparing byte arrays on each side, they are different, therefore image is not shown.

This is my (restful)webservice code for encoding image with base64

dto.setArti_image(new String(Base64.encode(rs.getBlob("arti_image"))));

result in byte[]

[B@270d42dc

And this is my code for decoding

byte[] image= Base64.decode(item.getArti_image(),Base64.NO_WRAP);
holder.imageItem.setImageBitmap(BitmapFactory.decodeByteArray(image, 0, image.length)                );

result in byte

[B@41079340 

Is this correct way of doing it or is there any more reliable way?

share|improve this question
1  
[B@270d42dc means [ Array, B => byte, @270d42dc the object's hashcode. This has nothing to do with it's content. Arrays.toString can be used to print the entire content of an array. –  zapl Oct 29 '14 at 18:14
    
Oh ok, didnt know that, thank you for explanation! Either way bitmapfactory returns SkImageDecoder:: Factory returned null. Just to make clear, is my method of sending image over WS ok? –  gregaj Oct 29 '14 at 19:32
1  
Code looks good (assuming the byte array contains compressed image data, like when you dump the content of a .jpg file into a byte array without decoding it). You should probably compare the content and see if it is transferred correctly. If it is, maybe your webservice has corrupt data already. You can also try to download the data into a file, the look at it with regular image viewers. (there are even tools like motobit.com/util/base64-decoder-encoder.asp that can turn base64 string into files, just name it .jpg or whatever it is) –  zapl Oct 29 '14 at 19:49
    
Thank you! I'll report back tomorrow :) –  gregaj Oct 29 '14 at 20:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.