如何检索PIM联系人的照片作为位图使用RIM5.0? [英] How to retrieve PIM contact's photo as Bitmap using RIM5.0?

查看:215
本文介绍了如何检索PIM联系人的照片作为位图使用RIM5.0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索联系人的图像和 BitmapField 显示它们秒。结果
所以我收集从联系人Bitmap对象,使用这种code:

I want to retrieve contacts' images and display them in BitmapFields.
So I'm collecting Bitmap objects from contacts, using this code:

Vector bitmaps = new Vector();
BlackBerryContactList contactList = (BlackBerryContactList)BlackBerryPIM.getInstance().openPIMList(BlackBerryPIM.CONTACT_LIST, BlackBerryPIM.READ_WRITE);
Enumeration contactListItems = contactList.items();
int counter = 0;
while (contactListItems.hasMoreElements()) {
    BlackBerryContact contact = (BlackBerryContact)contactListItems.nextElement();
    byte[] imageBytes = contact.getBinary(BlackBerryContact.PHOTO, counter);
    EncodedImage encodedImage = EncodedImage.createEncodedImage(imageBytes, 0, imageBytes.length);
    Bitmap bitmap = encodedImage.getBitmap();
    bitmaps.addElement(bitmap);
    counter++;
}

不幸的是,code抛出一个 java.lang.IllegalArumentException 在此方法:

EncodedImage.createEncodedImage(imageBytes, 0, imageBytes.length);

我如何转换768,16 字节[] 图片 BitmapField

推荐答案

我发现那些有兴趣谁,来自PIM检索到的图像解决方案采用Base64 EN codeD,应该是去codeD第一。下面是正确的code:

I found the solution for those who are interested, images retrieved from PIM are Base64 encoded, it should be decoded first. Here's the correct code:

Vector bitmaps = new Vector();
BlackBerryContactList contactList = (BlackBerryContactList)BlackBerryPIM.getInstance().openPIMList(BlackBerryPIM.CONTACT_LIST, BlackBerryPIM.READ_WRITE);
Enumeration contactListItems = contactList.items();
while (contactListItems.hasMoreElements()) {
    BlackBerryContact contact = (BlackBerryContact)contactListItems.nextElement();
    byte[] imageBytesBase64 = contact.getBinary(BlackBerryContact.PHOTO, 0);
    byte[] imageBytes = Base64InputStream.decode(imageBytesBase64, 0, imageBytesBase64.length);
    EncodedImage encodedImage = EncodedImage.createEncodedImage(imageBytes, 0, imageBytes.length);
    Bitmap bitmap = encodedImage.getBitmap();
    bitmaps.addElement(bitmap);
}

这篇关于如何检索PIM联系人的照片作为位图使用RIM5.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆