【问题标题】:Using IFMXCameraService.TakePhoto, is there a way of getting the image path?使用 IFMXCameraService.TakePhoto,有没有办法获取图像路径?
【发布时间】:2017-02-14 06:43:31
【问题描述】:

这是我正在使用的代码。

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;

显然来自:

http://docwiki.embarcadero.com/RADStudio/en/List_of_FireMonkey_Message_Types

在 fmx.platform 中找到了 TMessageReceivedImagePath。 但是我在任何地方都找不到它。我正在使用 10.1 Berlin update 2。我在 Embarcadero 论坛上发布了这个(感谢 Remy 的回答),但我希望有人能在这里找到答案。

PS/我还想存储抓拍图片的日期时间。

与此同时,我有一个解决方法,但它很难看,而且由于拍摄照片的秒精度计时,我确信它不会总是有效。

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;

【问题讨论】:

  • 我之前给你的答案有什么问题?订阅TMessageReceivedImagePath 消息是解决方案,那么您遇到的实际问题是什么?
  • 问题是在任何单元都找不到TMessageReceivedImagePath。所以是的,只要可以找到 TMessageReceivedImagePath,您提供的所有代码和解决方案都可以使用。
  • 您可以使用FormatDateTime() 而不是切分DateTimeToStr() 的结果:ImagePath := FormatDateTime('"IMG_"yyyymmdd"_"hhnnss".jpg"', Now);

标签: firemonkey delphi-10.1-berlin


【解决方案1】:

正如我在Embarcadero forum 上所说,您所要做的就是订阅TMessageReceivedImagePath 消息,例如:

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 记录消息在FMX.Platform 单元中。如果在那里找不到它,请检查它是在 FMX.Platform.Android 单元(因为它是特定于 Android 的消息)还是 FMX.MediaLibrary 单元(它定义了其他照片/视频捕获消息)中。

【讨论】:

  • 如论坛中所述,我无法在任何单元中找到 TMessageReceivedImagePath。即使使用“查找声明”也找不到任何东西。
  • 好的,你已经在 uses 子句中声明了 fmx.platform 和 fmx.platform.android 然后它找到了。什么任务:(我想如果你声明父级它应该在下面找到所有子级组件?
  • @sandman FMX.Platform.Android 不是 FMX.Platform 的子代。单位没有父/子关系。而且在找东西的时候,我更喜欢使用 $(BDS)\Source 文件夹中的“Find in Files”。
猜你喜欢
  • 1970-01-01
  • 2011-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-26
  • 1970-01-01
  • 2012-07-30
相关资源
最近更新 更多