Android实例-拍摄和分享照片、分享文本(XE8+小米2)
结果:
1.分享文本不好使,原因不明。有大神了解的,请M我,在此十分感谢。
2.如果想支持图片编辑,将Action事件的Editable改为True。
相关资料:
官网地址:http://docwiki.embarcadero.com/RADStudio/XE7/en/Mobile_Tutorial:_Taking_and_Sharing_a_Picture,_and_Sharing_Text_(iOS_and_Android)
实例代码:
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, FMX.StdCtrls, 8 FMX.Controls.Presentation, System.Actions, FMX.ActnList, FMX.Objects, 9 FMX.StdActns, FMX.MediaLibrary.Actions, FMX.ScrollBox, FMX.Memo; 10 11 type 12 TForm1 = class(TForm) 13 ToolBar1: TToolBar; 14 Button1: TButton; 15 Button2: TButton; 16 Button3: TButton; 17 Image1: TImage; 18 ActionList1: TActionList; 19 TakePhotoFromCameraAction1: TTakePhotoFromCameraAction; 20 TakePhotoFromLibraryAction1: TTakePhotoFromLibraryAction; 21 ShowShareSheetAction1: TShowShareSheetAction; 22 Button4: TButton; 23 Memo1: TMemo; 24 ShowShareSheetAction2: TShowShareSheetAction; 25 procedure TakePhotoFromCameraAction1DidFinishTaking(Image: TBitmap); 26 procedure TakePhotoFromLibraryAction1DidFinishTaking(Image: TBitmap); 27 procedure ShowShareSheetAction1BeforeExecute(Sender: TObject); 28 procedure ShowShareSheetAction2BeforeExecute(Sender: TObject); 29 private 30 { Private declarations } 31 public 32 { Public declarations } 33 end; 34 35 var 36 Form1: TForm1; 37 38 implementation 39 40 {$R *.fmx} 41 {$R *.NmXhdpiPh.fmx ANDROID} 42 43 //分享图片 44 procedure TForm1.ShowShareSheetAction1BeforeExecute(Sender: TObject); 45 begin 46 ShowShareSheetAction1.Bitmap.Assign(Image1.Bitmap); 47 end; 48 49 //分享文本 50 procedure TForm1.ShowShareSheetAction2BeforeExecute(Sender: TObject); 51 begin 52 ShowShareSheetAction1.TextMessage:= Memo1.Lines.Text; 53 end; 54 55 //调用相机 56 procedure TForm1.TakePhotoFromCameraAction1DidFinishTaking(Image: TBitmap); 57 begin 58 Image1.Bitmap.Assign(Image); 59 end; 60 61 //使用图片库 62 procedure TForm1.TakePhotoFromLibraryAction1DidFinishTaking(Image: TBitmap); 63 begin 64 Image1.Bitmap.Assign(Image); 65 end; 66 67 end.
请发表评论