Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

How to add image to contact

vishalvishal Posts: 76Registered Users
Hi,

I am trying to add image to a contact but could not add it.
Following is my code can anyone help me here?


CGImageRef sourceImageRef = [currentImage CGImage];
CFDataRef photoDataRef = CGDataProviderCopyData(CGImageGetDataProvider(sourceImageRef));

ABRecordRef newPerson = ABPersonCreate();
ABPersonSetImageData(newPerson, photoDataRef, nil);
ABRecordSetValue(newPerson, kABPersonFirstNameProperty, @\"John\", nil);
ABRecordSetValue(newPerson, kABPersonLastNameProperty, @\"Doe\", nil);

ABNewPersonViewController *ab = [[ABNewPersonViewController alloc] init];
[ab setNewPersonViewDelegate:self];
ab.displayedPerson = newPerson;

navController = [[UINavigationController alloc] initWithRootViewController:ab];
[ab release];

[self presentModalViewController:navController animated:YES];
[navController release];


I can add single record without photo, but when tried to add with photo record gets added but photo is not displayed.

I am using function "ABPersonSetImageData" to add the image, what format it requires?

Vishal N
Post edited by vishal on

Replies

  • vishalvishal Posts: 76Registered Users
    vishal;76967 said:
    Hi,

    I am trying to add image to a contact but could not add it.
    Following is my code can anyone help me here?


    CGImageRef sourceImageRef = [currentImage CGImage];
    CFDataRef photoDataRef = CGDataProviderCopyData(CGImageGetDataProvider(sourceImageRef));

    ABRecordRef newPerson = ABPersonCreate();
    ABPersonSetImageData(newPerson, photoDataRef, nil);
    ABRecordSetValue(newPerson, kABPersonFirstNameProperty, @\"John\", nil);
    ABRecordSetValue(newPerson, kABPersonLastNameProperty, @\"Doe\", nil);

    ABNewPersonViewController *ab = [[ABNewPersonViewController alloc] init];
    [ab setNewPersonViewDelegate:self];
    ab.displayedPerson = newPerson;

    navController = [[UINavigationController alloc] initWithRootViewController:ab];
    [ab release];

    [self presentModalViewController:navController animated:YES];
    [navController release];


    I can add single record without photo, but when tried to add with photo record gets added but photo is not displayed.

    I am using function "ABPersonSetImageData" to add the image, what format it requires?

    Vishal N
    Hi,

    I have got the solution for this.

    We need to create the PNG representation of the image.


    NSData * dataRef = UIImagePNGRepresentation(newImage);

    and add this to the records

    ABPersonSetImageData(newPerson, (CFDataRef)dataRef, nil);


    It adds the image to the record.

    Vishal N
Sign In or Register to comment.