Here is the code I am using.
procedure TForm1.getpic;
var
Service: IFMXCameraService;
Params: TParamsPhotoQuery;
begin
if TPlatformServices.Current.SupportsPlatformService(IFMXCameraService,
Service) then
begin
Params.Editable := false;
Params.NeedSaveToAlbum := True;
Params.RequiredResolution := TSize.Create(640,640);
Params.OnDidFinishTaking := DoDidFinishTakePic;
Service.TakePhoto(nil, Params);
end
else
xShowMessage('This device does not support the camera service');
end;
procedure TForm1.DoDidFinishTakePic(Image: TBitmap);
var
Imagepath:string;
begin
Image1.Bitmap.Assign(Image);
Imagepath := fmx.platform.TMessageReceivedImagePath;
end;
Apparently from:
http://docwiki.embarcadero.com/RADStudio/en/List_of_FireMonkey_Message_Types
there is TMessageReceivedImagePath found in fmx.platform. However I cannot find it anywhere. I am using 10.1 Berlin update 2. I posted this on the Embarcadero forum (thank you Remy for answer) but I am hoping someone has an answer here.
PS/ I would also like to store the DateTime of the picture captured.
In the mean time I have a workaround but it's ugly and I'm sure won't always work due to second-accuracy timing of the Take Photo.
procedure TForm1.DoDidFinishTakePic(Image: TBitmap);
var
Imagepath:string;
begin
Image1.Bitmap.Assign(Image);
st := datetimetostr(System.SysUtils.Now,xfs);
Imagepath := 'IMG_'+copy(st,1,4)+copy(st,6,2)+copy(st,9,2)+'_'+copy(st,12,2)+copy(st,15,2)+copy(st,18,2)+'.jpg';
end;
As I stated on the Embarcadero forum, all you have to do is subscribe to the TMessageReceivedImagePath
message, eg:
TMessageManager.DefaultManager.SubscribeToMessage(TMessageReceivedImagePath, DoMessageListener);
...
procedure TForm1.DoMessageListener(const Sender: TObject; const M: TMessage);
var
ImagePath: string;
begin
if M is TMessageReceivedImagePath then
begin
ImagePath := TMessageReceivedImagePath(M).Value;
...
end;
end;
Embarcadero documents the message is in the FMX.Platform
unit. If you can't find it there, check if it is in the FMX.Platform.Android
unit (since it is an Android-specific message) or the FMX.MediaLibrary
unit (which defines the other photo/video capture messages).