{************************************************************************** 名称: BaseImage 参数: fn: TFilename 返回值: string 功能: 将fn文件转换成Base64编码,返回值为编码 **************************************************************************} function BaseImage(fn: string): string; var m1: TMemoryStream; m2: TStringStream; str: string; begin m1 := TMemoryStream.Create; m2 := TStringStream.Create; m1.LoadFromFile(fn); EncdDecd.EncodeStream(m1, m2); str := m2.DataString; str := StringReplace(str, #13, ‘‘, [rfReplaceAll]); str := StringReplace(str, #10, ‘‘, [rfReplaceAll]); result := str; m1.Free; m2.Free; end;
转成base64后,MemoryStream比原图的流小,便于上传,节省时间。
时间: 2024-10-12 12:02:43