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
TfrmMain =
class(TForm)
tbMain: TToolBar;
btnCaptureImage: TSpeedButton;
btnSelectImage: TSpeedButton;
imgMain: TImage;
procedure btnCaptureImageClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure btnSelectImageClick(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
frmMain: TfrmMain;
implementation
{$R *.fmx}
procedure TfrmMain.DoDidFinish(Image: TBitmap);
begin
showmessage('
bild wird gemalt');
imgMain.Bitmap.Assign(Image);
end;
procedure TfrmMain.DoMessageListener(
const Sender: TObject;
const M: TMessage);
begin
if M
is TMessageDidFinishTakingImageFromLibrary
then
begin
imgMain.Bitmap.Assign(TMessageDidFinishTakingImageFromLibrary(M).Value);
end;
end;
procedure TfrmMain.FormShow(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) = 3)
and (AGrantResults[0] = TPermissionStatus.Granted)
and (AGrantResults[1] = TPermissionStatus.Granted)
and (AGrantResults[2] = TPermissionStatus.Granted)
then
TDialogService.ShowMessage('
permissions granted')
else
begin
TDialogService.ShowMessage('
permissions not granted');
end;
end
);
end;
procedure TfrmMain.btnCaptureImageClick(Sender: TObject);
var
Service: IFMXCameraService;
Params: TParamsPhotoQuery;
begin
if TPlatformServices.Current.SupportsPlatformService(IFMXCameraService,
Service)
then
begin
Params.Editable := True;
Params.NeedSaveToAlbum := True;
Params.RequiredResolution := TSize.Create(640, 640);
Params.OnDidFinishTaking := DoDidFinish;
Service.TakePhoto(btnCaptureImage, Params);
end
else
ShowMessage('
This device does not support the camera service');
end;
procedure TfrmMain.btnSelectImageClick(Sender: TObject);
var
ImageService: IFMXTakenImageService;
Params: TParamsPhotoQuery;
begin
if TPlatformServices.Current.SupportsPlatformService(IFMXTakenImageService,
IInterface(ImageService))
then
begin
Params.RequiredResolution := TSize.Create(640, 640);
Params.OnDidFinishTaking := DoDidFinish;
ImageService.TakeImageFromLibrary(btnSelectImage, Params);
end;
end;
end.