First, doing String.getBytes() involves converting the string into
some random encoding. You may know what encoding it happens to be on
Android devices, and perhaps it even won't change depending on what
country the device is being used in -- but me, I would never go NEAR
that method. Do not use it for any purpose; any use of it is sure to
be a bug. I have fixed an ENORMOUS number of bugs in people's code,
where the sole cause was calling this method.

Originally, your data is received via SAX as a char[] array, not a
string. That would be closer to what you want, in theory --- but:

Critical point: YOU CANNOT SEND UNENCODED BINARY DATA VIA XML. It's
not just that some characters have to be quoted. Some byte sequences
are not legal characters. When encountering these, a conforming parser
with throw an exception -- because it is not XML.

If the web service is actually doing this, the web service needs to be
redone.

More likely, the web service is sending the data encoded; for example,
it could be using Base64 encoding. You can work with this as a string
if you want (though that involves extra memory usage), but you have to
decode it to get the byte[] you'll need to construct the bitmap.

On Mar 8, 3:38 am, Paolo <[email protected]> wrote:
> I have a problem with this method "decodeByteArray()" when i try to
> decode from a byte array an image as a Bitmap.
>
> I explain it better:
> I receive from a web server an XML file, which also contains a
> thumbnail and some data.
> I parse this file with SAX, so I can build an object populated with
> all data, thumbnail included, as String.
>
> Then I need to set the thumbnail into a ImageView, so I convert the
> thumbanil string to byteArray with getBytes() and use it in this way:
>
> byte[] dataImg = thumbnail_string.getBytes();
>
> Bitmap b = BitmapFactory.decodeByteArray(dataImg, 0, dataImg.length);
>
> At this point b is null and I can't set it into the ImageView.
> I think it could be a problem of encoding/decoding.... any suggestions?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to