標籤:
結果:
1.如果要取本地相刪除的話,小米手機要注意一下,不能取網路相簿。
操作:
1.兩個 TButton (Button1 和 Button2) , 一個 TActionList(ActionList1) ,一個 TImage(Image1)。
2.Button1 的 stylelookup 選 擇 cameratoolbutton , Button1 的 stylelookup 選擇organizetoolbutton。
3.雙擊 ActionList1,在彈出的對話方塊中點擊右鍵菜單中的new standard action,然後選擇TakePhotoFromLibraryAction( 從圖片庫中選擇照片)和TakePhotoFromCameraAction(通過相機拍攝照片),這樣就加入了兩個標準的 Action。
4.在 TakePhotoFromCameraAction1 的 onDidFinishTaking 事件中寫如下代碼:
Image1.Bitmap.Assign(Image);
同樣,在 TakePhotoFromLibraryAction1 的 onDidFinishTaking 事件中寫如下代碼:
Image1.Bitmap.Assign(Image);
5.Button1 的 Action 設定為 TakePhotoFromCameraAction1,Button2 的 Action 設定為TakePhotoFromLibraryAction1。
執行個體代碼:
1 unit Unit1; 2 3 interface 4 5 uses 6 System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, System.Actions, 8 FMX.ActnList, FMX.Objects, FMX.Controls.Presentation, FMX.StdCtrls, 9 FMX.MediaLibrary.Actions, FMX.StdActns;10 11 type12 TForm1 = class(TForm)13 Button1: TButton;14 Button2: TButton;15 Image1: TImage;16 ActionList1: TActionList;17 TakePhotoFromLibraryAction1: TTakePhotoFromLibraryAction;//手動增加的Action18 TakePhotoFromCameraAction1: TTakePhotoFromCameraAction;//手動增加的Action19 procedure TakePhotoFromLibraryAction1DidFinishTaking(Image: TBitmap);20 procedure TakePhotoFromCameraAction1DidFinishTaking(Image: TBitmap);21 private22 { Private declarations }23 public24 { Public declarations }25 end;26 27 var28 Form1: TForm1;29 30 implementation31 32 {$R *.fmx}33 {$R *.NmXhdpiPh.fmx ANDROID}34 35 //來自手機照相功能36 procedure TForm1.TakePhotoFromCameraAction1DidFinishTaking(Image: TBitmap);37 begin38 Image1.Bitmap.Assign(Image);39 end;40 41 //來自手機的本地相簿42 procedure TForm1.TakePhotoFromLibraryAction1DidFinishTaking(Image: TBitmap);43 begin44 Image1.Bitmap.Assign(Image);45 end;46 47 end.
Android執行個體-從照相機或圖庫擷取照片(XE8+小米2)