Adding a photo to a contact using TAddressBook in Berlin
In 10.1 Berlin, we introduced TAddressBook, a new FireMonkey component for creating, accessing and managing contacts on iOS and Android.
We have updated our existing FireMonkey contacts demo and added the ability to add a photo to each contact you create. This demo uses our built-in actions for selecting an image from the gallery or taking a photo using the camera on your device.
//Create a new contact procedure TForm1.ActionAddContactExecute(Sender: TObject); var Contact: TAddressBookContact; eMails: TContactEmails; Photo: TBitmapSurface; begin Contact := AddressBook1.CreateContact(FDefaultSource); try try Contact.FirstName := edtFirstName.Text; Contact.LastName := edtLastName.Text; if not Image1.Bitmap.Size.IsZero then begin Photo := TBitmapSurface.Create; try Photo.Assign(Image1.Bitmap); Contact.Photo := Photo; Image1.Bitmap.SetSize(0, 0); finally Photo.Free; end; end; AddressBook1.SaveContact(Contact); except on E: EAddressBookException do ShowMessage('Cannot create the contact.' + E.Message); end; finally end;
You can access the demos in our SourceForge repository:
Below are screenshots of the demo being deployed to the iOS Simulator. If you deploy this demo to a physical iOS or Android device, you will also see the camera icon to invoke the on-device camera to take a photo that you can then assign to a contact.
Please login first in order for you to submit comments