BlackBerry 10与字节阵列联系

Blackberry 10 contact pic to byte array

本文关键字:阵列 联系 字节 BlackBerry      更新时间:2023-10-16

我正在迁移应用程序。我必须将BlackBerry 10接触转移到Android。

我在转移联系图片方面遇到问题。我正在获取图片的URI,创建文件并尝试读取字节。

ContactPhoto contactPhoto = contact.primaryPhoto();
QString photo = contactPhoto.originalPhoto();
//photo = file:///accounts/1000/pimdata/_startup_data/contacts/2/img-tnqpx0.jpg
if (!photo.isEmpty()){
    QFile file(photo);
    if (file.open(QIODevice::ReadOnly)) {
       qDebug() <<"file.readAll() IF" <<file.readAll() <<endl;
    }else{
       qDebug() <<"file.readAll() ELSE" <<endl;
    }
    vcardString += "PHOTO;JPEG;ENCODING=BASE64:" + (file.readAll() + "n");
}

但是,以下代码剪辑的部分是执行

if (file.open(QIODevice::ReadOnly)) {
    qDebug() <<"file.readAll() IF" <<file.readAll() <<endl;
}else{
    qDebug() <<"file.readAll() ELSE" <<endl;
}

我如何从下面读取字节

file:///accounts/1000/pimdata/_startup_data/contacts/2/img-tnqpx0.jpg

正如我所怀疑的,从URL删除file://

这是我用来测试的代码:

    bb::pim::contacts::ContactPhoto contactPhoto = contact.primaryPhoto();
    QString photo = contactPhoto.originalPhoto();
    if (!photo.isEmpty()){
        QFile file(photo.remove("file://"));
        if (file.open(QIODevice::ReadOnly)) {
           qDebug() <<"file.readAll() IF" <<file.readAll() <<endl;
        }else{
           qDebug() <<"file.readAll() ELSE" <<endl;
        }
    }

请注意,您需要在URL前留一个/,因此您在OP中共享的图片URL看起来像:

/accounts/1000/pimdata/_startup_data/contacts/2/img-tnqpx0.jpg

另外,如果您的目标是创建VCARD VCF文件,则无需手动创建VCARD文件内容,甚至不需要读取照片文件的字节,contactToVCard函数将对你。

QByteArray vcard = contactService.contactToVCard(contact.id(), bb::pim::contacts::VCardPhotoEncoding::BASE64, -1);
qDebug() << "vcard:" << vcard;