unit Camera;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.MediaLibrary, FMX.
Platform, System.Messaging,
FMX.Objects, FMX.StdCtrls, FMX.Controls.Presentation, System.Permissions,FMX.DialogService,
{$IFDEF ANDROID}
Androidapi.Jni.Os,
Androidapi.Helpers
{$ENDIF};
type
TForm1 =
class(TForm)
ToolBar1: TToolBar;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
Image1: TImage;
procedure SpeedButton1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
FPermissionCamera:
string;
FPermissionReadStorage:
string;
FPermissionWriteStorage:
string;
procedure DoDidFinish(Image: TBitmap);
procedure DoMessageListener(
const Sender: TObject;
const M: TMessage);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.DoDidFinish(Image: TBitmap);
begin
Image1.Bitmap.Assign(Image);
end;
procedure TForm1.DoMessageListener(
const Sender: TObject;
const M: TMessage);
begin
if M
is TMessageDidFinishTakingImageFromLibrary
then
Image1.Bitmap.Assign(TMessageDidFinishTakingImageFromLibrary(M).Value);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FPermissionCamera := JStringToString(TJManifest_permission.JavaClass.CAMERA);
FPermissionReadStorage := JStringToString(TJManifest_permission.JavaClass.READ_EXTERNAL_STORAGE);
FPermissionWriteStorage := JStringToString(TJManifest_permission.JavaClass.WRITE_EXTERNAL_STORAGE);
PermissionsService.RequestPermissions([FPermissionCamera,FPermissionReadStorage,FPermissionWriteStorage],
procedure(
const APermissions: TArray<
string>;
const AGrantResults: TArray<TPermissionStatus>)
begin
if (Length(AGrantResults) = 1)
and (AGrantResults[0] = TPermissionStatus.Granted)
then
TDialogService.ShowMessage('
permission granted')
else
begin
TDialogService.ShowMessage('
permission not granted');
end;
end
);
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
Service: IFMXCameraService;
Params: TParamsPhotoQuery;
begin
if TPlatformServices.Current.SupportsPlatformService(IFMXCameraService,
Service)
then
begin
Params.Editable := True;
// Specifies whether to save a picture to device Photo Library
Params.NeedSaveToAlbum := True;
Params.RequiredResolution := TSize.Create(640, 640);
Params.OnDidFinishTaking := DoDidFinish;
Service.TakePhoto(SpeedButton1, Params);
end
else
ShowMessage('
This device does not support the camera service');
end;
end.