C++ Blackberry 10联系人pic到字节数组
我正在开发迁移应用程序。我必须将blackberry 10联系人转移到android 我在传送联系人照片时遇到问题。我正在获取pic的uri,创建文件并尝试读取字节C++ Blackberry 10联系人pic到字节数组,c++,qt,contact,blackberry-10,C++,Qt,Contact,Blackberry 10,我正在开发迁移应用程序。我必须将blackberry 10联系人转移到android 我在传送联系人照片时遇到问题。我正在获取pic的uri,创建文件并尝试读取字节 ContactPhoto contactPhoto = contact.primaryPhoto(); QString photo = contactPhoto.originalPhoto(); //photo = file:///accounts/1000/pimdata/_startup_data/contacts/2/img-
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");
}
ContactPhoto ContactPhoto=contact.primaryPhoto();
QString photo=contactPhoto.originalPhoto();
//照片=file:///accounts/1000/pimdata/_startup_data/contacts/2/img-tnqpx0.jpg
如果(!photo.isEmpty()){
QFile文件(照片);
if(file.open(QIODevice::ReadOnly)){
qDebug()正如我所怀疑的,从url中删除文件://
是有效的
下面是我用来测试的代码:
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;
}
}
此外,如果您的目标是创建VCard vcf文件,则不需要手动创建VCard文件内容,甚至不需要读取照片文件的字节,那么contactToVCard
功能将为您完成此操作
QByteArray vcard = contactService.contactToVCard(contact.id(), bb::pim::contacts::VCardPhotoEncoding::BASE64, -1);
qDebug() << "vcard:" << vcard;
QByteArray vcard=contactService.contactToVCard(contact.id(),bb::pim::contacts::VCardPhotoEncoding::BASE64,-1);
qDebug()我刚刚检查了我的应用程序文件系统,我能够读取“/accounts/1000/pimdata/\u startup\u data/contacts/”子文件夹中的所有图片。我还没有看过代码,因为我不在家,但它可能与您正在使用的很接近,您可以尝试使用或不使用“file:/”吗看看它是否有区别。稍后我会看我的代码,如果我发现不同的东西,我会发布。谢谢Roger Leblanc,我正在准备VCARD,你告诉我关于API是很棒的。用这个API,我用所有的手工准备把它清除掉。
/accounts/1000/pimdata/_startup_data/contacts/2/img-tnqpx0.jpg
QByteArray vcard = contactService.contactToVCard(contact.id(), bb::pim::contacts::VCardPhotoEncoding::BASE64, -1);
qDebug() << "vcard:" << vcard;