图像到字符串 Delphi XE7 Android 和 Ios
Image To String Delphi XE7 Android and Ios
我正在 Delphi Xe7 FireMonkey 上使用 WebSevices 编写移动应用程序。
我在网络服务上有一个网络方法。该网络方法是 post Base64 字符串到我的数据库。
Delphi 这边是从位图创建这个 Base64 字符串。
我使用这个算法
Uses ....EncdDecd;
function Tfrm_yenikayit.BitmapToBase64(Bitmap: TBitmap): string;
var
Input : TMemoryStream;
Output: TStringStream;
begin
Input := TMemoryStream.Create;
try
Bitmap.SaveToStream(Input);
Input.Position := 0;
Output := TStringStream.Create('');
try
EncdDecd.EncodeStream(Input, Output);
Result := Output.DataString;
finally
Output.Free;
end;
finally
Input.Free;
end;
end;
但是一张尺寸为 1920x1280 的照片给出了大约 300 万个字符的结果。
如何将图像制作成比这个算法更快的短字符串?
我找到了 algortihym
的解决方案
Function BitmapToBase64(Bitmap:Tbitmap):string;
var
BS: TBitmapSurface;
AStream: TMemoryStream;
AStringStream : TStringStream;
AResult : AnsiString;
begin
BS := TBitmapSurface.Create;
BS.Assign(Bitmap);
BS.SetSize(600,400);///Solution this
AStream := TMemoryStream.Create;
try
TBitmapCodecManager.SaveToStream(AStream, BS, '.jpg');
AStringStream := TStringStream.Create(EncodeBase64(AStream, AStream.Size));
Result:=AStringStream.DataString;
finally
AStream.Free;
AStringStream.Free;
BS.Free;
end;
end;
我找到了解决方案BS.SetSize(600,400)
,它对我来说并不重要
我正在 Delphi Xe7 FireMonkey 上使用 WebSevices 编写移动应用程序。 我在网络服务上有一个网络方法。该网络方法是 post Base64 字符串到我的数据库。 Delphi 这边是从位图创建这个 Base64 字符串。 我使用这个算法
Uses ....EncdDecd;
function Tfrm_yenikayit.BitmapToBase64(Bitmap: TBitmap): string;
var
Input : TMemoryStream;
Output: TStringStream;
begin
Input := TMemoryStream.Create;
try
Bitmap.SaveToStream(Input);
Input.Position := 0;
Output := TStringStream.Create('');
try
EncdDecd.EncodeStream(Input, Output);
Result := Output.DataString;
finally
Output.Free;
end;
finally
Input.Free;
end;
end;
但是一张尺寸为 1920x1280 的照片给出了大约 300 万个字符的结果。 如何将图像制作成比这个算法更快的短字符串?
我找到了 algortihym
的解决方案Function BitmapToBase64(Bitmap:Tbitmap):string;
var
BS: TBitmapSurface;
AStream: TMemoryStream;
AStringStream : TStringStream;
AResult : AnsiString;
begin
BS := TBitmapSurface.Create;
BS.Assign(Bitmap);
BS.SetSize(600,400);///Solution this
AStream := TMemoryStream.Create;
try
TBitmapCodecManager.SaveToStream(AStream, BS, '.jpg');
AStringStream := TStringStream.Create(EncodeBase64(AStream, AStream.Size));
Result:=AStringStream.DataString;
finally
AStream.Free;
AStringStream.Free;
BS.Free;
end;
end;
我找到了解决方案BS.SetSize(600,400)
,它对我来说并不重要