04-20-2010 01:49 AM
Hi.. I am trying to fetch photo from a particular contact. I can see from the built in application that picture is there but not able to fetch it. Its giving Illegal Argument Exception. I am not getting where is the problem.. here is the code.. please suggest where i m wrong ??
public static byte[] getPic(Contact contact) // This is the function for fetching byte data in the Picture class
{
byte[] pic = null;
if(contact == null)
{
return null;
}
if((contact.countValues(Contact.PHOTO) > 0))
{
pic = new byte[(int)(contact.getBinary(Contact.PHOTO,0).leng th)];
pic = contact.getBinary(Contact.PHOTO, 0);
}
return pic;
}
if(Picture.getPic(item)!=null) // item is the contact
{
EncodedImage image = EncodedImage.createEncodedImage(Picture.getPic(ite m), 0,
Login.getPic(item).length);
}The function createEncodedImage is not working. I have tried createBitmapFromBytes also. But that isn't working too.
Please suggest some solution.
Thanx
Solved! Go to Solution.
04-20-2010 06:50 AM
Drom the API documentation:
"Note that the javadocs for addBinary(), setBinary(), and getBinary() all state that the binary data must be encoded "in a "B" binary encoded string as defined by [IETF RFC 2047]". This means that the photo data returned from getBinary() will be Base64-encoded. Also, data may be specified to setBinary() and addBinary() in either raw bytes or Base64-encoded; if raw bytes are specified then they are converted to Base64. To encode or decode Base64 data you may use Base64OutputStream or Base64InputStream, respectively."
In otherwords you need to undo the Base64 encoding first.
04-21-2010 08:03 AM
Thanks rcmaniac25.. It really helped. I didn't take that line seriously.