I'm trying to convert from ByteString to Image once i receive the ByteString from Socket Connection.
A string which I received from Socket Connection onMessage
[size=302697hex=7c53657276657252657475726e4469723d54454d505f4449527c496d61676546696c654e616d653d496d6167655f3030312e6a70677c030905ffd8ffe000104a…]
How can I get the image from the above ByteString?
I tried to convert this string to Base64 URL, Byte Array but not worked for me.
Please help me to get out of this.
Thanks in Advance.
you need to first convert the hex string to byte array, then decode Base64 (not sure if required), then convert to image. If you can share a full sample string response, I check and verify the steps, and share the code.
you can use https://stackoverflow.com/a/18714790/11535103 to convert the hex string to byte array
Related
what would be most efficient way to display a image received as bytearray in json response. I am currently using volley to download the response and use my own caching implementation. Is there a way to use any of the existing libraries like Picasso to display the images ?
The string is a Base64 encoded byte array. Use Base64.decode to decode it to byte[] and then construct a Bitmap from the byte[].
I find the next possible ways
1) convert Image into Base64 string and put this string into the JSON object.
Send image as json entry android
2) create an array of bytes out of the bitmap, and then create a new string with that array of bytes, and then send it to the server
http://blog.3dmick.com/2012/06/android-app-for-uploading-images-on-server/
Which else libraries or ways do u know ??
Which ways are popular on the enteptise projects?
send some image data in base64 and collect in hanlder and get message object in handler.
How can collect that image base64 data in handler and how to change that data into byte array after that base64.
Thanks in advance.
To decode the base64 data to a byte array, use this utility.
Is there a mechanism in Android, which allows us to convert a large image into a Hex String Array before we send it to a webservice over the network?
I know how to convert it to a byte array and transfer it but I'm not so confident on how to implement the same using a Hex String.
Thanks in advance.
No direct method to do this. Convert to byte[] first. Then, convert to hex string like in answers to question "In Java, how do I convert a byte array to a string of hex digits while keeping leading zeros?"
friends,
i am using ksoap library to call dotnet webservice.
i am getting following webservice reponse
<imageByte>R0lGODlhlgBQAPcAAKPBqfP69Ja0m32hgxdVJdrb28zMzPr+/QRKEdPi1IGliL3PwCFXLP38+YSJhPr7+</imageByte>
<imageByte>R0lGODlhlgBQAPcAAKPBqfP69Ja0m32hgxdVJdrb28zMzPr+/QRKEdPi1IGliL3PwCFXLP38+YSJhPr7+</imageByte>
<imageByte>R0lGODlhlgBQAPcAAKPBqfP69Ja0m32hgxdVJdrb28zMzPr+/QRKEdPi1IGliL3PwCFXLP38+YSJhPr7+</imageByte>
removed some extra bytes from string because it was very lengthy.
1) i dont know which format it is.
2) how to convert it to byte[] to display it in android imageview.
any help would be appreciated.
This may be base64 encoding; at least it looks like the right mix of characters. The specific webservice docs should tell you more about the message format.
Assuming it is, and that one image is broken into multiple <imageByte /> tags, combine the contents into one long string. You can then use Base64.decode to get a byte[], and BitmapFactory.decodeByteArray to get a Bitmap handle, which you pass to ImageView.setImageBitmap
Hope this helps,
Phil Lello