BlackBerry 10与字节阵列联系
Blackberry 10 contact pic to byte array
我正在迁移应用程序。我必须将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;
相关文章:
- OpenMP阵列性能较差
- 如何将三维尺寸不固定的三维阵列展平为一维阵列
- 当我的阵列太大时出现分段错误
- 位阵列上的快速AND运算
- 阵列必须使用大括号封闭的初始器进行初始化
- 没有从阵列<float>到阵列<int>的可行转换
- C++动态安全 2D 交错阵列
- 将平面阵列重塑为复杂的特征类型
- 如何使用英特尔 PIN 捕获阵列的所有负载?
- 为什么我能够为阵列分配比计算机实际拥有的内存更多的内存
- 库特<<恩德尔;不适用于打印 2D 阵列
- 数组类 阵列的打印输出
- 从较小的阵列到较大的阵列的元素级转换
- 仅在大型阵列上出现合并排序分段错误
- 从阵列C++中删除重复项
- 阵列的大小在C++中是否灵活?
- 反转阵列中的正序列
- 具有可变尺寸的 C++ 2D 阵列
- 二维阵列的动态分配
- BlackBerry 10与字节阵列联系