How to send an image as a Hex String Array in Android? - android

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?"

Related

How to convert ByteString to Image in Android?

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

android.utils.Base64.encode gets different value

When I try this:
map.put("password1", Base64.encode("111111".getBytes(),Base64.DEFAULT));
map.put("password2", Base64.encode("111111".getBytes(),Base64.DEFAULT));
map.put("password3", Base64.encode("111111".getBytes(),Base64.DEFAULT));
I got different value of password1,password2 and password3:
password1:[B#5368aecc
password2:[B#536e9ea0
password3:[B#536c0dec
Is it should be the same value?
Thanks in advance.
You're essentially printing toString() of a byte[] array. The output is different for different byte array objects.
Either don't store the values as byte arrays by removing the .getBytes(), or convert your byte arrays back to string with new String(byteArray, someEncoding).
Yes, its can be same , when u add a some text to your string, the old part of string is in hashed string same. Check more at Wikipedia

ways and usefull libraries for sending image from client (android) to server (Spring)

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?

android Reading image into byte array and last byte of image

Android:
I have two byte arrays one byte array of bitmap and another byte array of String.
I have combine these two byte arrays into 3rd one.
I will write 3rd byte array into storage.
When i read that image which is created from combine byte array of image and string i want to know in byte[] that where image bytes ends and where string bytes gets start.
How do i know the byte representation of end of image byte ? or starting of string byte ?
Thanks in advance.
Before you write out the byte array, you should write out the length of the image part. That way you'll know how much data to read. So your file will look like this:
Length of image (4 bytes, probably - use DataOutputStream for simplicity)
Image data
Text data
(As an aside, I suggest you explicitly write out the text data as UTF-8, and read it as UTF-8. Or you could just use DataOutputStream.writeUTF and DataInputStream.readUTF of course...)

how to convert imagebytes to byte[] in android using ksoap?

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

Categories

Resources