代码之家  ›  专栏  ›  技术社区  ›  Hüseyin Okumuş

图像到字符串Delphi XE7 Android和Ios

  •  -1
  • Hüseyin Okumuş  · 技术社区  · 11 年前

    我在Delphi Xe7 FireMonkey上用WebSevices编程mobil应用程序。 我在webservice上有一个webmethod。该webmethod将Base64字符串发布到我的数据库。 Delphi Side从Bitmap创建这个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万人的惊喜。 如何使图像变短,比这个算法更快?

    1 回复  |  直到 11 年前
        1
  •  0
  •   David Heffernan    11 年前

    我找到了解决疼痛的方法

    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) 这对我来说并不重要