28-12-2019, Saat: 16:13
Merhaba
OrangeUI Takefrompicture sample üzerinden çalışma yapıyorum. Ama ilk seçenek kamerayı açma seçeneğini bir türlü yapamadım.
Kamera açılmıyor. Standart Actionlist ile de denememde kameryı açamadın uses permission kkısmında kamera seçili olmasına rağmen.
İkinci seçenek olan galeriden seçme işleminde ise seçilen foroğrafı alamadım.SkinFMXPicture ın içine seçili fotoyu nasıl atabilirim?
Değerli fikirlerinizi duymak sterim.

OrangeUI Takefrompicture sample üzerinden çalışma yapıyorum. Ama ilk seçenek kamerayı açma seçeneğini bir türlü yapamadım.
Kamera açılmıyor. Standart Actionlist ile de denememde kameryı açamadın uses permission kkısmında kamera seçili olmasına rağmen.
İkinci seçenek olan galeriden seçme işleminde ise seçilen foroğrafı alamadım.SkinFMXPicture ın içine seçili fotoyu nasıl atabilirim?
Değerli fikirlerinizi duymak sterim.

//convert pas to utf8 by ¥
unit TakePictureMenuFrame;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
uUIFunction,
uVersion,
uSkinItems,
uFuncCommon,
uLang,
uBaseLog,
uFrameContext,
uSkinFireMonkeyEdit,
uSkinFireMonkeyMemo,
uProcessNativeControlModalShowPanel,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
uSkinFireMonkeyButton, uSkinFireMonkeyControl, uSkinFireMonkeyPanel,
uSkinFireMonkeyLabel, uSkinFireMonkeyImage, FMX.Controls.Presentation,
uSkinAnimator, uSkinFireMonkeyScrollControl, uSkinFireMonkeyVirtualList,
uSkinFireMonkeyListBox, FMX.MediaLibrary.Actions, System.Actions,
FMX.ActnList, FMX.StdActns, uSkinFireMonkeyCustomList, uSkinButtonType,
uSkinScrollControlType, uSkinCustomListType, uSkinVirtualListType,
uSkinListBoxType, uBaseSkinControl, uSkinPanelType;
type
THideMenuType=(hmtNone,hmtHasPicture);
TTakedPictureEvent=procedure(Sender:TObject;ABitmap:TBitmap) of object;
TFrameTakePictureMenu = class(TFrame,
IFrameChangeLanguageEvent,
IFrameHistroyReturnEvent)
pnlBackground: TSkinFMXPanel;
pnlBottom: TSkinFMXPanel;
lbMenu: TSkinFMXListBox;
scmaPopup: TSkinControlMoveAnimator;
ActionList: TActionList;
ActionTakePhotoFromLibrary: TTakePhotoFromLibraryAction;
ActionTakePhotoFromCamera: TTakePhotoFromCameraAction;
btnUseInIPadSetPosition: TSkinFMXButton;
procedure FrameResize(Sender: TObject);
procedure pnlBackgroundClick(Sender: TObject);
procedure ActionTakePhotoFromLibraryDidFinishTaking(Image: TBitmap);
procedure ActionTakePhotoFromCameraDidFinishTaking(Image: TBitmap);
procedure lbMenuClickItem(Sender: TSkinItem);
procedure scmaPopupAnimateEnd(Sender: TObject);
private
FRawBitmap: TBitmap;
HideMenuType:THideMenuType;
procedure TakePhotoFromCamera;
procedure TakePhotoFromAlbum;
{ Private declarations }
protected
procedure ChangeLanguage(ALangKind:TLangKind);
protected
function CanReturn:Boolean;
public
OnTakedPicture:TTakedPictureEvent;
procedure HideMenu;
procedure ShowMenu;
public
FrameHistroy:TFrameHistroy;
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
{ Public declarations }
end;
var
GlobalTakePictureMenuFrame:TFrameTakePictureMenu;
procedure CopyBitmap(ASrcBitmap:TBitmap;ADestBitmap:TBitmap);
implementation
uses uOgrenciDetay;
procedure CopyBitmap(ASrcBitmap:TBitmap;ADestBitmap:TBitmap);
begin
ADestBitmap.SetSize(ASrcBitmap.Width,ASrcBitmap.Height);
ADestBitmap.Canvas.BeginScene();
try
ADestBitmap.Canvas.Clear(0);
ADestBitmap.Canvas.DrawBitmap(
ASrcBitmap,
RectF(0,0,ASrcBitmap.Width,ASrcBitmap.Height),
RectF(0,0,ADestBitmap.Width,ADestBitmap.Height),
1
);
finally
ADestBitmap.Canvas.EndScene;
end;
end;
{$R *.fmx}
{ TFrameTakePictureMenu }
procedure TFrameTakePictureMenu.TakePhotoFromAlbum;
var
Image:TBitmap;
OpenDialog: TOpenDialog;
I: Integer;
begin
// uBaseLog.OutputDebugString('aa','');
{$IFDEF MSWINDOWS}
OpenDialog := TOpenDialog.Create(nil);
try
OpenDialog.Filter := TBitmapCodecManager.GetFilterString;
OpenDialog.Options:=OpenDialog.Options+[TOpenOption.ofAllowMultiSelect];
if OpenDialog.Execute then
begin
for I := 0 to OpenDialog.Files.Count-1 do
begin
Image:=TBitmap.CreateFromFile(OpenDialog.Files[I]);
ActionTakePhotoFromLibraryDidFinishTaking(Image);
uFuncCommon.FreeAndNil(Image);
end;
end;
finally
uFuncCommon.FreeAndNil(OpenDialog);
end;
{$ENDIF}
{$IFNDEF MSWINDOWS}
//btnUseInIPadSetPosition
ActionTakePhotoFromLibrary.ExecuteTarget(btnUseInIPadSetPosition);
{$ENDIF}
//{$IF DEFINED(IOS) or DEFINED(ANDROID)}
// ActionTakePhotoFromLibrary.ExecuteTarget(btnUseInIPadSetPosition);
// {$ENDIF}
end;
procedure TFrameTakePictureMenu.TakePhotoFromCamera;
var
Image:TBitmap;
OpenDialog: TOpenDialog;
I: Integer;
begin
// uBaseLog.OutputDebugString('拍照','');
//拍照
{$IFDEF MSWINDOWS}
OpenDialog := TOpenDialog.Create(nil);
try
OpenDialog.Filter := TBitmapCodecManager.GetFilterString;
OpenDialog.Options:=OpenDialog.Options+[TOpenOption.ofAllowMultiSelect];
if OpenDialog.Execute then
begin
for I := 0 to OpenDialog.Files.Count-1 do
begin
Image:=TBitmap.CreateFromFile(OpenDialog.Files[I]);
ActionTakePhotoFromLibraryDidFinishTaking(Image);
uFuncCommon.FreeAndNil(Image);
end;
end;
finally
uFuncCommon.FreeAndNil(OpenDialog);
end;
{$ENDIF}
{$IFNDEF MSWINDOWS}
try
ActionTakePhotoFromCamera.ExecuteTarget(Self);
except
on E:Exception do
begin
uBaseLog.HandleException(E,'ActionTakePhotoFromCamera.ExecuteTarget');
end;
end;
{$ENDIF}
{$IF DEFINED(IOS) or DEFINED(ANDROID)}
try
ActionTakePhotoFromCamera.ExecuteTarget(Self);
except
on E:Exception do
begin
uBaseLog.HandleException(E,'ActionTakePhotoFromCamera.ExecuteTarget');
end;
end;
{$ENDIF}
end;
procedure TFrameTakePictureMenu.ActionTakePhotoFromCameraDidFinishTaking(Image: TBitmap);
var
ScaleFactor: Single;
begin
if Image.Width > 1024 then
begin
ScaleFactor := Image.Width / 1024;
Image.Resize(Round(Image.Width / ScaleFactor), Round(Image.Height / ScaleFactor));
end;
// FRawBitmap.Assign(Image);
CopyBitmap(Image,FRawBitmap);
HideMenuType:=hmtHasPicture;
HideMenu;
end;
procedure TFrameTakePictureMenu.ActionTakePhotoFromLibraryDidFinishTaking(Image: TBitmap);
var
ScaleFactor: Single;
begin
if Image.Width > 1024 then
begin
ScaleFactor := Image.Width / 1024;
Image.Resize(Round(Image.Width / ScaleFactor), Round(Image.Height / ScaleFactor));
end;
// FRawBitmap.Assign(Image);
CopyBitmap(Image,FRawBitmap);
HideMenuType:=hmtHasPicture;
HideMenu;
end;
procedure TFrameTakePictureMenu.HideMenu;
begin
scmaPopup.GoForward;
end;
procedure TFrameTakePictureMenu.ShowMenu;
begin
//先隐藏原生控件
//设置Edit的ControlType,避免MessageBoxFrame被原生控件挡住
SetGlobalEditListAsStyleType;
SetGlobalMemoListAsStyleType;
ProcessNativeControlBeginModalShow;
Self.pnlBackground.Visible:=True;
Self.pnlBackground.Align:=TAlignLayout.alNone;
Self.pnlBackground.SetBounds(0,0,Width,Height);
Self.lbMenu.Width:=Width;
Self.pnlBackground.BringToFront;
scmaPopup.GoBackward;
end;
procedure TFrameTakePictureMenu.scmaPopupAnimateEnd(Sender: TObject);
begin
if Self.scmaPopup.DirectionType=adtForward then
begin
//隐藏弹出菜单结束
Self.pnlBackground.Visible:=False;
Self.Visible:=False;
//一定要放在隐藏WaitingFrame的后面
//还原所有的Edit的ControlType为Platform
RestoreGlobalEditListAsPlatformType;
RestoreGlobalMemoListAsPlatformType;
//先隐藏WaitingFrame,再还原,免得WaitingFrame被盖住
ProcessNativeControlEndModalShow;
HideFrame(Self,hfcttBeforeReturnFrame,ufsefNone);
ReturnFrame(Self);
case HideMenuType of
hmtHasPicture:
begin
if Assigned(OnTakedPicture) then
begin
OnTakedPicture(Self,FRawBitmap);
end;
end;
end;
end;
end;
function TFrameTakePictureMenu.CanReturn: Boolean;
begin
if Self.Visible then
begin
Result:=False;
HideMenu;
end
else
begin
//直接返回
Result:=True;
end;
end;
procedure TFrameTakePictureMenu.ChangeLanguage(ALangKind: TLangKind);
const
Langs_Button_Caption_Camera : array[Low(TLangKind)..High(TLangKind)] of string =
('Fotoğraf Çekin','Take Photo','');
Langs_Button_Caption_Album : array[Low(TLangKind)..High(TLangKind)] of string =
('Galeriden Seçin','Select From Album','');
// Langs_Button_Caption_Cancel : array[Low(TLangKind)..High(TLangKind)] of string =
// ('从相册选择','Select From Album','');
Langs_Button_Caption_CANCEL : array[Low(TLangKind)..High(TLangKind)] of string =
('Kapat','Cancel','');
begin
//翻译
Self.lbMenu.Properties.Items.FindItemByName('btnFoto').Caption:=Langs_Button_Caption_Camera[ALangKind];
Self.lbMenu.Properties.Items.FindItemByName('btnGaleri').Caption:=Langs_Button_Caption_Album[ALangKind];
Self.lbMenu.Properties.Items.FindItemByName('btnKapat').Caption:=Langs_Button_Caption_Cancel[ALangKind];
end;
constructor TFrameTakePictureMenu.Create(AOwner: TComponent);
begin
inherited;
FRawBitmap := TBitmap.Create(0, 0);
RecordSubControlsLang(Self);
TranslateSubControlsLang(Self);
end;
destructor TFrameTakePictureMenu.Destroy;
begin
uFuncCommon.FreeAndNil(FRawBitmap);
inherited;
end;
procedure TFrameTakePictureMenu.FrameResize(Sender: TObject);
begin
Self.pnlBackground.SetBounds(0,0,Width,Height);
Self.lbMenu.Width:=Width;
end;
procedure TFrameTakePictureMenu.lbMenuClickItem(Sender: TSkinItem);
begin
if TSkinItem(Sender).Name='btnFoto' then
begin
TakePhotoFromCamera;
end;
if TSkinItem(Sender).Name='btnGaleri' then
begin
TakePhotoFromAlbum;
end;
if TSkinItem(Sender).Name='btnKapat' then
begin
HideMenuType:=hmtNone;
HideMenu;
end;
end;
procedure TFrameTakePictureMenu.pnlBackgroundClick(Sender: TObject);
begin
OnTakedPicture:=nil;
HideMenuType:=hmtNone;
HideMenu;
end;
end.