AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Cross-Platform-Entwicklung Fmx Mobile IFMXCameraService TakePhoto

Fmx Mobile IFMXCameraService TakePhoto

Ein Thema von Rollo62 · begonnen am 30. Okt 2015 · letzter Beitrag vom 4. Nov 2015
Antwort Antwort
Rollo62
Online

Registriert seit: 15. Mär 2007
3.882 Beiträge
 
Delphi 12 Athens
 
#1

Fmx Mobile IFMXCameraService TakePhoto

  Alt 30. Okt 2015, 12:19
Hallo zusammen,

weiss jemand wofür hier der Parameter Control gut ist ?

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:
Service.TakePhoto(SpeedButton1, Params); //Was hat der Button damit zu tun ?
Natürlich löst der Button das aus, aber das Aufnehmen setzt doch nicht etwa rückwirkend irgendetwas im Button ?

Rollo
  Mit Zitat antworten Zitat
Benutzerbild von Mavarik
Mavarik

Registriert seit: 9. Feb 2006
Ort: Stolberg (Rhld)
4.123 Beiträge
 
Delphi 10.3 Rio
 
#2

AW: Fmx Mobile IFMXCameraService TakePhoto

  Alt 30. Okt 2015, 14:16
"Normalerweise" ist das doch eine Action...

Nimm einen Button und dann die Action dran
  Mit Zitat antworten Zitat
Rollo62
Online

Registriert seit: 15. Mär 2007
3.882 Beiträge
 
Delphi 12 Athens
 
#3

AW: Fmx Mobile IFMXCameraService TakePhoto

  Alt 30. Okt 2015, 15:14
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
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#4

AW: Fmx Mobile IFMXCameraService TakePhoto

  Alt 30. Okt 2015, 15:54
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;
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
Rollo62
Online

Registriert seit: 15. Mär 2007
3.882 Beiträge
 
Delphi 12 Athens
 
#5

AW: Fmx Mobile IFMXCameraService TakePhoto

  Alt 4. Nov 2015, 09:21
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:
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.
Rollo

Geändert von Rollo62 ( 4. Nov 2015 um 10:06 Uhr)
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:41 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz