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
Developer
simon_hain
Posts: 15,947
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany
Accepted Solution

Read and display the photo of a addressbook contact

i want to display the photo of a contact. i have set one of the sample pictures on the simulator.

byte[] b = blackberryContact.getBinary(BlackBerryContact.PHOTO, 0);
System.out.println("b lenght: " + b.length);
EncodedImage e = EncodedImage.createEncodedImage(b, 0, b.length);
BitmapField bf = new BitmapField();
bf.setImage(e);

i get the output
b lenght: 3556
followed by an IllegalArgumentException, according to API: If the image format is not recognized, an IllegalArgumentException is thrown.

How do i get the byte[] from the BlackBerryContact to the correct format to be used with createEncodedImage ?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Administrator
MSohm
Posts: 14,362
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Read and display the photo of a addressbook contact

This is caused by an issue with the BlackBerry handheld software and has been fixed in version 4.5.0.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
simon_hain
Posts: 15,947
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Read and display the photo of a addressbook contact

i use jde 4.6.0.12 and the bold simulator that is part of the package. is there a newer version available?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Administrator
MSohm
Posts: 14,362
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Read and display the photo of a addressbook contact

The photo is stored in base64 format, which your code is not handling.  Have a look at the JavaDocs for the javax.microedition.pim.Contact class for an example.  Sorry for not catching that the first time. 

 

This should also work on previous versions.  The issue I thought this related to only applies when saving a contact.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
simon_hain
Posts: 15,947
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Read and display the photo of a addressbook contact

thanks, that solved it. if i have looked at the 4.5/4.6 api instead of the old 4.2.1 one i would have seen it myself.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.