![]() |
Fmx Mobile IFMXCameraService TakePhoto
Hallo zusammen,
weiss jemand wofür ![]()
Code:
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([B]SpeedButton1[/B], Params); [B]//Was hat der Button damit zu tun ?[/B] end else ShowMessage('This device does not support the camera service'); end; Zitat:
Rollo |
AW: Fmx Mobile IFMXCameraService TakePhoto
"Normalerweise" ist das doch eine Action...
Nimm einen Button und dann die Action dran |
AW: Fmx Mobile IFMXCameraService TakePhoto
Hallo Mavarik,
ja, aber was wenn ich auch programmgesteuert ein Bild machen möchte ? Bevor du fragst: ich erwarte in einem View ein Bild zur Bearbeitung, also damit das vorher da ist möchte ich das programmgesteuert knipsen. Damit der Nutzer weiss was er als erstes machen müsste. Da hilft mir der Button nicht weiter. Weder mit der TakePhotoFromCameraAction geht das, noch mit den Services s.u. Natürlich benutzt TakePhotoFromCamera das Gleiche im Prinzip, also sollte es irgendwie funktionieren, nut tut es das nicht. Bin noch auf der Suche nach einer Lösung ... FYI: Alle Versuche die Action von Hand zu feuern sind bisher gescheitert. Rollo |
AW: Fmx Mobile IFMXCameraService TakePhoto
Starten, Button drücken, Foto machen und übernehmen, Bild anschauen.
Delphi-Quellcode:
type
TForm1 = class( TForm ) SpeedButton1: TSpeedButton; ImageControl1: TImageControl; procedure SpeedButton1Click(Sender: TObject); private procedure PhotoDidFinishTaking(Image:TBitmap); procedure PhotoDidCancelTaking; end; procedure TCameraComponentForm.PhotoDidCancelTaking; begin // Was auch immer hier passieren soll end; procedure TCameraComponentForm.PhotoDidFinishTaking(Image: TBitmap); begin ImageControl1.Bitmap.Assign(Image); end; procedure TCameraComponentForm.SpeedButton1Click(Sender: TObject); var service : IFMXCameraService; begin if TPlatformServices.Current.SupportsPlatformService(IFMXCameraService,service) then begin service.TakePhoto( nil, TSize.Create(200,200), False, PhotoDidFinishTaking, PhotoDidCancelTaking ); end; end; |
AW: Fmx Mobile IFMXCameraService TakePhoto
Hallo Sir Rufo,
dankesehr für die Erkenntnis, manchmal kommt man nur mit einem nil so richtig weiter :-) Trotzdem verstehe ich immer noch nicht wozu der Parameter überhaupt da ist. Naja, ich habe hier man versucht den ganzen Kram zu vereinfachen so das man für ein Foto einfach das hier aufrufen kann:
Code:
TS4TakePhoto.Execute(TSize.Create(EditPhotoSize.Text.ToInteger,
EditPhotoSize.Text.ToInteger), procedure (const bmpPhoto : TBitmap) begin Image1.Bitmap.Assign(bmpPhoto); TextPhotoResult.Text := 'Result W: ' + bmpPhoto.Width.ToString + ', H: ' + bmpPhoto.Height.ToString + Format(' Scale %1.4f', [bmpPhoto.BitmapScale]) ; end ); Der Parameter Size funktioniert, aber scheint auf ein Maximum je nach Device begrenzt zu sein. Kennt jemand den Trick wie man das Maximum vorher abfragen kann ? UPDATE: Ich haber gerade auf Android bei einem Galaxy S5 getestet mit Size(500, 500) bekomme ich nur ein Bmp mit (230, 408) BitmapScale = 1 zurück. Also auf iOS scheint (bis jetzt) Size zu stimmen, auf Android schonmal nicht. Wie bekommt man das Ganze 1:1 hin auf allen Platformen ? Hier die ganze Unit
Code:
Rollo
unit S4.Media.Photo;
interface uses System.Types, System.SysUtils , FMX.Graphics ; // // Class for triggering the camera dialog and taking a picture from Camera // // // Usage: // TS4TakePhoto.Execute(TSize.Create(EditPhotoSize.Text.ToInteger, // EditPhotoSize.Text.ToInteger), // procedure (const bmpPhoto : TBitmap) // begin // Image1.Bitmap.Assign(bmpPhoto); // // TextPhotoResult.Text := 'Result W: ' + bmpPhoto.Width.ToString + // ', H: ' + bmpPhoto.Height.ToString + // Format(' Scale %1.4f', [bmpPhoto.BitmapScale]) // ; // // end, // procedure // begin // ShowMessage('Take Photo was cancelled'); // end // ); // or // // TS4TakePhoto.Execute(TSize.Create(EditPhotoSize.Text.ToInteger, // EditPhotoSize.Text.ToInteger), // procedure (const bmpPhoto : TBitmap) // begin // Image1.Bitmap.Assign(bmpPhoto); // // TextPhotoResult.Text := 'Result W: ' + bmpPhoto.Width.ToString + // ', H: ' + bmpPhoto.Height.ToString + // Format(' Scale %1.4f', [bmpPhoto.BitmapScale]) // ; // // end // ); type TS4TakePhotoResultProc = reference to procedure (const bmpPhoto : TBitmap); TS4TakePhoto = class private class var _Single : TS4TakePhoto; class var procResult : TS4TakePhotoResultProc; class var procCancel : TProc; procedure EvDidCancelTaking; procedure EvDidFinishTaking(Image: TBitmap); protected class destructor Destroy; public destructor Destroy; override; // // sizeBmp defines the desired image size, but is limited to device maximum, // bmp tries to BestFit into cx, cy with keeping the AspectRatio // // Returns True if TakePhoto triggered // Returns False if CameraServiuce unavailable // class function Execute(const sizeBmp : TSize; const prResult : TS4TakePhotoResultProc; const prCancel : TProc = nil) : Boolean; end; implementation Uses FMX.MediaLibrary , FMX.Platform ; class destructor TS4TakePhoto.Destroy; begin FreeAndNil( _Single ); end; destructor TS4TakePhoto.Destroy; begin inherited; end; procedure TS4TakePhoto.EvDidCancelTaking; begin if Assigned(procCancel) then procCancel; end; procedure TS4TakePhoto.EvDidFinishTaking(Image: TBitmap); begin if Assigned(procResult) then procResult( Image ); end; class function TS4TakePhoto.Execute(const sizeBmp : TSize; const prResult : TS4TakePhotoResultProc; const prCancel : TProc) : Boolean; var ICameraService : IFMXCameraService; parCam : TParamsPhotoQuery; begin if not Assigned(_Single) then _Single := TS4TakePhoto.Create; _Single.procResult := prResult; _Single.procCancel := prCancel; if TPlatformServices.Current.SupportsPlatformService(IFMXCameraService, ICameraService) then begin parCam.RequiredResolution := sizeBmp; parCam.Editable := False; parCam.NeedSaveToAlbum := False; parCam.OnDidFinishTaking := _Single.EvDidFinishTaking; parCam.OnDidCancelTaking := _Single.EvDidCancelTaking; ICameraService.TakePhoto(nil, parCam); ICameraService := nil; Result := True; end else begin Result := False;// No CameraService available end; end; end. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:45 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz