导航:
论坛 -> 移动应用开发
斑竹:flyers,iamdream
作者:
chec (chec)
★☆☆☆☆
-
普通会员
2014/5/18 13:55:26
标题:
加入我的收藏
楼主:
昨天进一步研究了samples,通过按钮的stylelookup设置,可以非常方便的实现打开文件,分享图片,调用照相机等。我想实现,在路上拍张照,连同经纬度一起实时传到服务器上的功能,不知道有没有人知道,上传怎么弄,有个思路就行。
----------------------------------------------
-
作者:
2014/5/18 14:03:10
1楼:
你就当你抱着一台 WINDOWS 笔记本做刚才的操作。你用 DELPHI 写不出上传?
----------------------------------------------
(C)(P)Flying Wang
作者:
chec (chec)
★☆☆☆☆
-
普通会员
2014/5/18 17:45:41
2楼:
datasnap,以前用的是loadfromfile(路径)存入blob,现在只看到assign(image),学得不是很精,不知道行不行?有时间再尝试吧!
----------------------------------------------
-
作者:
chec (chec)
★☆☆☆☆
-
普通会员
2014/5/18 17:47:00
3楼:
win平台下,有打开文件对话框,andriod下没有的。
----------------------------------------------
-
作者:
2014/5/18 18:08:03
4楼:
打开文件对话框目前需要自己做。
----------------------------------------------
(C)(P)Flying Wang
作者:
2014/5/18 20:16:55
5楼:
用快驴,可以轻松做文件传输哦 1、示例代码 // // 开始上传... procedure TForm1.Button5Click(Sender: TObject); var j: integer; tmpstr: string; begin tmpstr:=edit2.Text; j:=pos('\',tmpstr); while j>0 do begin delete(tmpstr,1,j); j:=pos('\',tmpstr); end; memo2.Lines.Add('本地文件='+localpath+tmpstr); if mbftp.UploadFile(localpath+tmpstr,trim(edit2.Text),0) then begin t0:=now; memo2.Lines.Add('文件上传已启动!'); end else memo2.Lines.Add('启动文件上传失败!Error='+mbftp.LastError); end; // // 上传进度... procedure TForm1.MBFtpUploadProgress(MaxBlocks, OkBlocks: Integer); begin progressbar2.Max:=MaxBlocks; progressbar2.Value:=OkBlocks; end; // // 上传成功... procedure TForm1.MBFtpUploadCompleted(Sender: TObject); var fa: TFileAttribute; j: integer; x: TDateTime; begin x:=now; application.ProcessMessages; if files.GetFileAttribute(trim(edit2.Text),fa) then j:=fa.FileSize else j:=0; memo2.Lines.Add('上传完成!速度='+formatfloat('0.00',j/1024/1024/((x-t0)*24*60*60))+'MB/秒'); end; 2、运行效果
此帖子包含附件: 大小: 174.1K
----------------------------------------------
樵夫的大马甲
作者:
2014/5/18 20:21:29
6楼:
至于选择文件,也简单的(这个不需要三层组件): 1、代码 unit OpenPictureDialog; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, System.Rtti, FMX.StdCtrls, FMX.Objects, FMX.Layouts, FMX.Grid, FMX.ListBox, System.IoUtils; type TOpenPictureForm = class(TForm) ToolBar1: TToolBar; CornerButton1: TCornerButton; Panel1: TPanel; FileGrid: TStringGrid; StringColumn1: TStringColumn; StringColumn2: TStringColumn; StringColumn3: TStringColumn; Button1: TButton; Button2: TButton; Panel2: TPanel; Image1: TImage; Rectangle1: TRectangle; procedure FormShow(Sender: TObject); procedure showfilelist; procedure Button1Click(Sender: TObject); procedure FormResize(Sender: TObject); procedure FileGridSelChanged(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } mode: integer; {1: 群聊 2:私聊} dir,selectedfilename: string; ImageWidth,ImageHeight: single; end; var OpenPictureForm: TOpenPictureForm; implementation uses login,main; {$R *.fmx} // // 返回... procedure TOpenPictureForm.Button1Click(Sender: TObject); begin close; end; // // 发送... procedure TOpenPictureForm.Button2Click(Sender: TObject); begin if FileGrid.Selected<0 then begin ShowMessage('请先选择需要发送的图片文件!'); exit; end; selectedfilename:=mainform.s_favdir+FileGrid.Cells[1,FileGrid.Selected]; mainform.sendtimer.Enabled:=true; close; end; // // 选择不同图片时,预览... procedure TOpenPictureForm.FileGridSelChanged(Sender: TObject); begin image1.MultiResBitmap.Clear; if FileGrid.Selected>=0 then begin with image1.MultiResBitmap.Add do begin bitmap.LoadFromFile(mainform.s_favdir+FileGrid.Cells[1,FileGrid.Selected]); ImageWidth:=Bitmap.Width; ImageHeight:=Bitmap.Height; end; end; end; // // 自适应处理... procedure TOpenPictureForm.FormResize(Sender: TObject); begin panel2.Height:=(self.Height-toolbar1.Height)/2; StringColumn1.Width:=49/364*FileGrid.Width; StringColumn2.Width:=222/364*FileGrid.Width; StringColumn3.Width:=87/364*FileGrid.Width; end; // // 窗口显示时,列出文件... procedure TOpenPictureForm.FormShow(Sender: TObject); begin image1.MultiResBitmap.Clear; showfilelist; end; // // 显示文件列表... procedure TOpenPictureForm.showfilelist; var sr: TSearchRec; j: integer; ext: string; begin FileGrid.BeginUpdate; FileGrid.RowCount:=0; if System.SysUtils.FindFirst(mainform.s_favdir+'*',faAnyFile, sr) <> 0 then begin FileGrid.EndUpdate; exit; end; repeat if (sr.Attr and faDirectory)=0 then begin ext:=uppercase(ExtractFileExt(sr.Name))+','; if pos(ext,'.ICO,.BMP,.PNG,.JPG,.JPEG,.GIF,.WMF,.EMF,')>0 then begin j:=FileGrid.RowCount; FileGrid.RowCount:=FileGrid.RowCount+1; FileGrid.Cells[0,j]:=inttostr(j+1); FileGrid.Cells[1,j]:=sr.Name; FileGrid.Cells[2,j]:=inttostr(sr.Size); end; end; until System.SysUtils.FindNext(sr) <> 0; System.SysUtils.FindClose(sr); FileGrid.EndUpdate; if FileGrid.RowCount>0 then begin FileGrid.SelectRow(0); FileGridSelChanged(nil); end; end; end. 2、效果
此帖子包含附件: 大小: 264.4K
----------------------------------------------
樵夫的大马甲
作者:
2014/5/18 20:40:55
7楼:
拍了照再传输,也简单的 1、代码 // // 拍照结束... procedure TMainForm.TakePhotoFromCameraAction1DidFinishTaking(Image: TBitmap); var tmpfilename: string; Stream: TMemoryStream; MsgParcel: TMBParcel; // Topic: TSayItem; h,w,mw,mh,imgWidth,ImgHeight: single; // BodyType: string; begin Pad1.IsExpanded:=false; tmpfilename:=mainform.s_favdir+'_tmp_photo_.jpg'; imgWidth:=Image.Width; ImgHeight:=Image.Height; image.SaveToFile(tmpfilename); Stream:=TMemoryStream.Create; Stream.LoadFromFile(tmpfilename); BodyType:='Img'; // // 生成消息... MsgParcel:=TMBParcel.Create; MsgParcel.PutStringGoods('MsgFlag','mbtalking_msg_flag'); MsgParcel.PutStringGoods('MsgType','Public'); MsgParcel.PutStringGoods('BodyType',BodyType); MsgParcel.PutStringGoods('FromSessionId',MBConn.WebSessionId); MsgParcel.PutStringGoods('FromUserName',s_UserName); MsgParcel.PutStringGoods('FromUserSex',s_Sex); MsgParcel.PutIntegerGoods('FromUserHeaderIndex',s_HeaderIndex); Stream.Position:=0; MsgParcel.PutStreamGoods('ImageBody',Stream); MsgParcel.PutSingleGoods('ImageWidth',ImgWidth); MsgParcel.PutSingleGoods('ImageHeight',ImgHeight); FreeAndNil(Stream); // // 发送消息... if not Poster.PostToWebAllSessions(MsgParcel) then begin System.SysUtils.deletefile(tmpfilename); MsgParcel.Free; ShowMessage('发送消息失败,请稍后再试!'); exit; end; MsgParcel.Free; // // 发送成功,马上显示... Topic:=TSayItem.Create(nil); Topic.Width:=Show1.ClientWidth; Topic.Align:=TAlignLayout.Top; Topic.Margins.Top:=5; Topic.Margins.Bottom:=5; Topic.Margins.Left:=10; Topic.Margins.Right:=82; Topic.Subject.Text:=s_username+' '+formatdatetime('hh:nn:ss',now); Topic.Subject.TextSettings.FontColor:=s_SelfTextColor; // // 确定最佳大小... mw:=Show1.ClientWidth-144; mh:=Show1.Height/2; if mw>imgwidth then mw:=imgwidth; if mh>imgheight then mh:=imgheight; h:=mh; w:=h/imgheight*imgwidth; if w>mw then begin w:=mw; h:=w/imgwidth*imgheight; end; Topic.Body.Align:=TAlignLayout.None; Topic.Height:=h+42; Topic.Body.Height:=h+10; Topic.Body.Width:=w+24; Topic.Image.Width:=w; Topic.Image.Height:=h; Topic.Image.Margins.Top:=4; Topic.Image.Margins.Left:=4; Topic.Image.Margins.Right:=4; Topic.Image.Margins.Bottom:=4; Topic.Msg.Visible:=false; Topic.Image.Visible:=true; Topic.Image.Align:=TAlignLayout.Client; ShowImage(tmpfilename,Topic.Image); Topic.Body.Stroke.Color:=s_SelfTextColor; Topic.Body.Fill.Color:=s_SelfBackColor; ShowHeader(s_sex,true,s_HeaderIndex,Topic.Header); Show1.AddObject(Topic); System.SysUtils.deletefile(tmpfilename); end; 2、效果
此帖子包含附件: 大小: 259.3K
----------------------------------------------
樵夫的大马甲
作者:
2014/5/18 21:55:07
8楼:
樵夫你收他几万块,直接让他外包给你做算了。
----------------------------------------------
(C)(P)Flying Wang
作者:
chec (chec)
★☆☆☆☆
-
普通会员
2014/5/18 22:33:49
9楼:
樵帮主果然厉害,学个一招半式就够我用的了! 我想这招能用: image.SaveToFile(tmpfilename); Stream:=TMemoryStream.Create; Stream.LoadFromFile(tmpfilename); 先谢了! 建议樵帮主也出本书,解救苦苦摸索的delphi帮众!
----------------------------------------------
-
作者:
chec (chec)
★☆☆☆☆
-
普通会员
2014/5/18 22:51:22
10楼:
QuickBurro应该是很不错的东东!:-)
----------------------------------------------
-
作者:
2014/5/19 11:21:03
11楼:
用IDFTP上传吧
----------------------------------------------
欢迎加入OrangeUI For FMX 技术支持QQ群10900297
作者:
2014/5/19 14:17:39
12楼:
"通过按钮的stylelookup设置,可以非常方便的实现打开文件" 怎么实现的,设置stylelookup好像只能发改变按钮图标吧?
----------------------------------------------
-
作者:
chec (chec)
★☆☆☆☆
-
普通会员
2014/5/19 17:14:53
13楼:
你关于调用相机的Demo试试就知道了,还有些参数要设置的
----------------------------------------------
-