Base64.decode specific

1

I'm trying to load a string I get from the WebService into an ImageView of the Android. I made some comparisons and found that the string I get is correct, but it's a string and as such I can not load it into the imageView.

But by transforming it to a Bytes Array with

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

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

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

BitmapFactory.decodeByteArray( 

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

What method should I use to accomplish this: transform a byte string [] without change the content?

    
asked by anonymous 28.04.2017 / 20:37

1 answer

1

I finally got the answer.

This 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 answer for more information.

    
02.05.2017 / 14:43