RAD Studio 10.4.1 is now available! Learn more. Looking for discounts? Visit our Special Offers page!
C++

New FireMonkey Media Library Options in RAD Studio XE8

RAD Studio XE8 provides new FireMonkey Media Library options. This includes the ability to automatically save pictures taken by the device camera (in your iOS and Android applications) to the on-device photo library.

Today, I thought I would show you how to save photos taken with the device camera directly to your photo library by extending our ShareSheet code snippet demo that is included with RAD Studio XE8. This demo uses the built-in ShareSheet and TakePhoto actions, and utilizes the the IFMXPhotoLibrary interface for automatically saving the image to the camera roll.

Note: The ShareSheet code snippet can be found in the Mobile Snippets directory on your machine.

Image 

camera2_5f00_zpsd92j64q1-1715073

Image3

unit uMain;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Objects, FMX.StdCtrls,
  System.Actions, FMX.ActnList, FMX.StdActns, FMX.MediaLibrary.Actions, FMX.Graphics,
  FMX.Controls.Presentation;

type
  TShareSheetForm = class(TForm)
    ActionList1: TActionList;
    ShowShareSheetAction1: TShowShareSheetAction;
    Action1: TAction;
    TakePhotoFromCameraAction1: TTakePhotoFromCameraAction;
    TopToolbar: TToolBar;
    Label1: TLabel;
    BottomToolbar: TToolBar;
    btnShare: TButton;
    btnTakePhoto: TButton;
    imgCameraPicture: TImage;
    procedure ShowShareSheetAction1BeforeExecute(Sender: TObject);
    procedure TakePhotoFromCameraAction1DidFinishTaking(Image: TBitmap);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ShareSheetForm: TShareSheetForm;

implementation

{$R *.fmx}
{$R *.LgXhdpiPh.fmx ANDROID}

uses
FMX.Platform, FMX.MediaLibrary;

procedure TShareSheetForm.ShowShareSheetAction1BeforeExecute(Sender: TObject);
begin
   { Show the Share Sheet }
  ShowShareSheetAction1.Bitmap.Assign(imgCameraPicture.Bitmap);
end;


procedure TShareSheetForm.TakePhotoFromCameraAction1DidFinishTaking(Image: TBitmap);
var
  Service: IFMXPhotoLibrary;
begin
   { Assign the picture taken from the camera to the TImage control and save to the Library }
  imgCameraPicture.Bitmap.Assign(Image);
 if TPlatformServices.Current.SupportsPlatformService(IFMXPhotoLibrary, Service) then
    Service.AddImageToSavedPhotosAlbum(imgCameraPicture.Bitmap)
  else
    ShowMessage('The IFMXPhotoLibrary interface is not supported.');
end;
end.

Information from our DocWiki:

If your application handles pictures by using either the FireMonkey Actions or the IFMXCameraService interface, you can use the TCustomTakePhotoAction.NeedSaveToAlbum property or a parameter of the TParamsPhotoQuery type to cause your application to automatically save the pictures to the device Photo Library.
In addition, FireMonkey provides the IFMXPhotoLibrary interface that allows you to save any bitmap image to the device Photo Library.

For more information and code examples, see:


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

About author

Director of Product Management, Developer Tools Idera, Inc.
Related posts
DelphiRAD Studio

Get Started Building Cross-Platform Games In Delphi FireMonkey With Alien Invasion Sample

C++Delphi

Ultimate Compression Toolkit For Delphi And C++ Builder Developers

DelphiNews

RAD Studio with Delphi - The Original Low Code!

DelphiShowcase

KisKis The Crazy Social Network For Android And iOS In Delphi

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES