从地址簿中获取图片的裁剪版本

时间:2012-01-23 13:09:09

标签: objective-c ios cocoa abaddressbook abpeoplepickerview

我使用以下代码从地址簿加载联系人图片:

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{

    UIImage *image = [UIImage imageWithData:(NSData *)ABPersonCopyImageData(person)];

    return NO;
}

但是,此代码会返回存储的完整图像,而不是裁剪版本,它会显示在各种位置,例如地址簿。

1 个答案:

答案 0 :(得分:4)

我在这里找到答案:https://stackoverflow.com/a/6953492/784318

NSData *imageData = (__bridge NSData*)ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail);
UIImage *image = [UIImage imageWithData:imageData];