简体   繁体   English

黑莓10联系人图片到字节数组

[英]Blackberry 10 contact pic to byte array

I am working on migration application. 我正在开发迁移应用程序。 I have to transfer blackberry 10 contacts to android. 我必须将黑莓10联系人转移到android。

I am getting problem in transferring contact pic. 我在转移联系人照片时遇到问题。 I am getting the uri of the pic, create file and try to read the bytes. 我正在获取图片的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");
}

But else part of the below snip of code is executing 但是下面的代码片段的其他部分正在执行

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

How I read bytes from below uri 我如何从uri下面读取字节

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

As I suspected, removing file:// from the url works. 正如我所怀疑的,从URL中删除file://是可行的。

Here's the code I used to test : 这是我用来测试的代码:

    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;
        }
    }

Please note that you need to leave one / in front of the url, so your picture url shared in OP would look like : 请注意,您需要在网址前保留一个/ ,因此在OP中共享的图片网址应如下所示:

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

Also, if your goal is to create a VCard vcf file, you don't need to manually create the VCard file content, don't even need to read the bytes of the photo file, the contactToVCard function will do that for you. 另外,如果您的目标是创建VCard vcf文件,则无需手动创建VCard文件的内容,甚至不需要读取照片文件的字节, contactToVCard函数将为您完成此操作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM