• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Delphi文件转换Base64、Base64转换文件

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

 

相关资料:

https://www.cnblogs.com/h2285409/p/11714576.html

http://www.delphitop.com/html/jiami/4213.html

https://www.cnblogs.com/findumars/p/5789404.html

 

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Memo1: TMemo;
    Memo2: TMemo;
    Button3: TButton;
    Edit1: TEdit;
    OpenDialog1: TOpenDialog;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
uses
  EncdDecd;
{$R *.dfm}

function FileToBase64(FileName: string): string;
var
  MemoryStream: TMemoryStream;
begin
  Result := '';
  MemoryStream := TMemoryStream.Create;
  try
    MemoryStream.LoadFromFile(FileName);
    Result := EncodeBase64(MemoryStream.Memory, MemoryStream.Size);
    //base64默认有一个77字符后换行一次,用TCP发送时不方便,就去掉了回车换行。
    Result := StringReplace(Result, #13, '', [rfReplaceAll]);
    Result := StringReplace(Result, #10, '', [rfReplaceAll]);
  finally
    MemoryStream.Free;
  end;
end;

procedure Base64ToFile(AStr: string);
var
  MemoryStream: TMemoryStream;
begin
  MemoryStream := TMemoryStream.Create;
  try
    MemoryStream.Write(DecodeBase64(AStr), Length(DecodeBase64(AStr)));
    MemoryStream.SaveToFile('d:\11.txt');
  finally
    MemoryStream.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenDialog1.Execute() then
  begin
    Edit1.Text :=  OpenDialog1.FileName;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Memo1.Text := FileToBase64(Edit1.Text);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Base64ToFile(Memo1.Text);
end;

end.

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Matlab基本数据类型发布时间:2022-07-18
下一篇:
MATLAB与C#之间传递参数以及Matlab与C#连接的几种方式比较发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap