ABPersonSetImageData仅更改联系人缩略图而不是完整的图片 [英] ABPersonSetImageData Only Altering the Contact Thumbnail and Not the Full Pic

查看:166
本文介绍了ABPersonSetImageData仅更改联系人缩略图而不是完整的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在每张联系人照片周围添加边框。我有工作代码来创建这个有边框的图像和工作代码将其设置为联系人图像:

I am trying to add a border around each contact photo. I have working code to create this bordered image and working code to set it as the contact image:

if (image) {
    NSData *dataRef = UIImagePNGRepresentation(image); 
    CFDataRef cfdata = CFDataCreate(NULL, [dataRef bytes], [dataRef length]);
    CFErrorRef error;
    ret = ABPersonSetImageData(person, cfdata, &error);
    if (ret) {
        ret = ABAddressBookSave(addressBook, &error);
    } else {
        DebugLog(@"Could not write the image to the person: %@", [error description]);
    }
    CFRelease(cfdata);
}

我看到的问题是边框图像正确显示在在通讯录或手机应用中查看缩略图时,来电显示的全屏图片不是。

The problem I am seeing is that while the bordered image shows up correctly in the thumbnail when viewing in the Contacts or Phone app, the full-screen image displayed on an incoming call is not.

我原本以为它只是放大了一点所以我尝试边框大小。我确认边框在大镜头上根本没有显示。我错过了一些明显的东西吗?

I originally thought it was just zoomed in a little so I experimented with the border size. I confirmed that the border is not showing at all on the large shot. Am I missing something obvious?



编辑10/9/09
我一直在与Apple沟通,这确实是一个地址簿框架中的错误。如果您正在阅读这篇文章,那么我建议您向Apple提交错误以帮助加快修复。

推荐答案

我将在这里回答我自己的问题,因为我认为我弄清楚了问题是什么。如果您的联系人还没有图像,则在使用ABPersonSetImageData时,将添加缩略图和全尺寸镜头。如果您的联系人已经拥有一个完整大小的图像,那么当您使用ABPersonSetImageData时,只会设置缩略图。

I am going to answer my own question here as I think I figured out what is the issue. If your contact does NOT already have an image, both the thumbnail and the full sized shot will be added when you use ABPersonSetImageData. If your contact has a full-sized image already, ONLY the thumbnail will be set when you use ABPersonSetImageData.

实现这一点后,解决方案很简单。我只是在设置之前删除了图片。

After realizing this, the solution is a no-brainer. I just remove the pic right before setting it.

if (image) {
    NSData *dataRef = UIImagePNGRepresentation(image); 
    CFDataRef cfdata = CFDataCreate(NULL, [dataRef bytes], [dataRef length]);
    CFErrorRef error;

    ABPersonRemoveImageData(person, &error); // <-- clean any image first from ref
    ABAddressBookSave(addressBook, &error);

    ret = ABPersonSetImageData(person, cfdata, &error);
    if (ret) {
        ret = ABAddressBookSave(addressBook, &error);
    } else {
        DebugLog(@"Could not write the image to the person");
    }
    CFRelease(cfdata);
}

注意*这会创建一个正方形版本的全尺寸照片。该过程裁剪图像的顶部和底部,并将其设置为320x320。但是,它正在运作。

NOTE* This creates a square version of the full-sized pic. The process crops the top and bottom off of the image and sets it to be 320x320. But, it is working.

编辑10/9/09
我一直在与Apple进行通信,这确实是地址簿框架中的一个错误。如果您正在阅读这篇文章,那么我建议您向Apple提交错误以帮助加快修复。

EDIT 10/9/09 I have been in communications with Apple and this is indeed a bug in the Address Book framework. If you are reading this post, then I suggest you file a bug with Apple at to help expedite the fix.

这篇关于ABPersonSetImageData仅更改联系人缩略图而不是完整的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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