Get image of a person from iPhone address book

末鹿安然 提交于 2019-12-03 20:39:20

问题


How do you get a person's image from an iPhone address book?


回答1:


You can do it like this....

NSData  *imgData = (NSData *)ABPersonCopyImageData(person);

UIImage  *img = [UIImage imageWithData:imgData];

where person is of type ABRecordRef. Now, as CFData and NSData are toll-free bridged, you can simply type cast CFData to NSData and get the image

Hope this helps.




回答2:


(NSData*)ABPersonCopyImageDataWithFormat([targetPeople objectAtIndex:index], kABPersonImageFormatThumbnail)

This is faster since it returns a thumbnail.




回答3:


Slightly refreshed code:

UIImage *image = nil;

@try
{
    CFDataRef cfImage = ABPersonCopyImageData(person);
    // or CFDataRef cfImage = ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail);
    if (cfImage)
    {
        image = [UIImage imageWithData:(__bridge NSData*)cfImage];
        CFRelease(cfImage);
    }
}
@catch (NSException *exception)
{
    //...
}


来源:https://stackoverflow.com/questions/2085959/get-image-of-a-person-from-iphone-address-book

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!