Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
bb_develop
Posts: 61
Registered: ‎02-24-2010
My Device: Storm 2
My Carrier: AT&T
Accepted Solution

Getting picture using getBinary

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).length)];
			pic = contact.getBinary(Contact.PHOTO, 0);
		}
		return pic;
	}

if(Picture.getPic(item)!=null) // item is the contact
{
EncodedImage image = EncodedImage.createEncodedImage(Picture.getPic(item), 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

 

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1154, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Getting picture using getBinary

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.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Regular Contributor
bb_develop
Posts: 61
Registered: ‎02-24-2010
My Device: Storm 2
My Carrier: AT&T

Re: Getting picture using getBinary

Thanks rcmaniac25.. It really helped. I didn't take that line seriously.

Please use plain text.