结果:
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。
实例代码:
unit Unit1; interface uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, System.Actions,
FMX.ActnList, FMX.Objects, FMX.Controls.Presentation, FMX.StdCtrls,
FMX.MediaLibrary.Actions, FMX.StdActns; type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Image1: TImage;
ActionList1: TActionList;
TakePhotoFromLibraryAction1: TTakePhotoFromLibraryAction;//手动增加的Action
TakePhotoFromCameraAction1: TTakePhotoFromCameraAction;//手动增加的Action
procedure TakePhotoFromLibraryAction1DidFinishTaking(Image: TBitmap);
procedure TakePhotoFromCameraAction1DidFinishTaking(Image: TBitmap);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.fmx}
{$R *.NmXhdpiPh.fmx ANDROID} //来自手机照相功能
procedure TForm1.TakePhotoFromCameraAction1DidFinishTaking(Image: TBitmap);
begin
Image1.Bitmap.Assign(Image);
end; //来自手机的本地相册
procedure TForm1.TakePhotoFromLibraryAction1DidFinishTaking(Image: TBitmap);
begin
Image1.Bitmap.Assign(Image);
end; end.