Base64.Decode specific

Asked

Viewed 40 times

1

I’m trying to load a string I get from Webservice in an Imageview from Android. I made some comparisons and found that the string I receive is correct, however it is a string and as such I can not load to imageView.

But by transforming it into an Array of Bytes with

byte[] base64converted=   Base64.decode(lista.get(position).getImageData(),Base64.DEFAULT);

The string that was like this: FFD8FFE000104A46 4946000101000001, becomes that: 1450FC145134D34D 74E00E3AE3DE3AD3

I need them to be the same bytes. Be an object of type byte[], but have this content: FFD8FFE000104A46... and not this 1450FC145134D34D...

BitmapFactory.decodeByteArray( 

also does not work, it also changes the string bytes the same as string.getBytes() does.

Which method should I use to achieve this: turn a string into byte[] without change the content?

  • A little confused. Try this: http://stackoverflow.com/a/18571348/2570426

1 answer

1

I finally got the answer.

That function solved the question:

public static byte[] hexStringToByteArray(String s) {
    int len = s.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                             + Character.digit(s.charAt(i+1), 16));
    }
    return data;
}

Link to reply for more information.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.